7.0.4 • Published 12 months ago

@emoyly/problem v7.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Problem

UNDER DEVELOPMENT - NOT READY FOR PRODUCTION

Problem is an error handling library, based around the RFC-7807 standard, with support for additional parsers and middleware (Explained below). The library may not follow the standard completely in some cases. An example of which is that it currently only supports the JSON variant of problem details. There is also other features added, making it much more of an HTTP error handling framework, than just an implementation of the standard.

Terms

Middleware

Middleware catches errors occurring in a node module, like Express or Axios, and converts it into a Problem object.

Parsers

A parser converts common JS errors from various npm modules into Problem objects.

Usage & examples

Basic

TODO: Write a basic explanation of just implementing the library somehow

Express

    import { ExpressMiddleware } from '@emoyly/problem/middleware/express'

    const problemMiddleware = new ExpressMiddleware()

    events.onProblem(problems => {
        for (const problem of problems) {
            // If its a 4XX error or alike, we don't really need to log it
            if (problem.status < 500) continue
            // Log the error. This could be replaced with a function reporting the error to something like Sentry
            console.error(problem)
        }
    })

    // In your Express middleware ↓

    // Handles 404 errors
    app.use(problemMiddleware.notFound)

    // Responds in the right way
    app.use(problemMiddleware.use())

Axios

import axios from 'axios'
import { Problem } from '@emoyly/problem'
import { AxiosMiddleware } from '@emoyly/problem/middleware/axios'

const api = axios.create({
    'baseURL': `example.com`,
})

const middleware = new AxiosMiddleware()

api.interceptors.response.use(...middleware.use())
6.0.0

1 year ago

7.0.0

12 months ago

7.0.4

12 months ago

7.0.3

12 months ago

7.0.2

12 months ago

7.0.1

12 months ago

5.0.6

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

5.0.8

2 years ago

5.0.7

2 years ago

4.1.12

3 years ago

4.1.11

3 years ago

4.1.10

3 years ago

4.1.9

3 years ago

4.1.8

3 years ago

4.1.7

3 years ago

4.1.6

3 years ago

4.1.5

3 years ago