|
1 | 1 | /** |
2 | | - * Options of `error-http-response` |
| 2 | + * The options and the return value have the same shape |
| 3 | + * ([RFC 7807](https://www.rfc-editor.org/rfc/rfc7807)). Options can be passed |
| 4 | + * either as an argument to |
| 5 | + * [`errorHttpResponse()`](#errorhttpresponseerror-options) or be set to |
| 6 | + * `error.http`. |
| 7 | + * |
| 8 | + * Options are validated: an exception is thrown if their syntax is invalid. |
3 | 9 | */ |
4 | 10 | export interface Options { |
5 | 11 | /** |
6 | | - * URI identifying and documenting the error class. Ideally, each error class |
7 | | - * [should set one](https://github.com/ehmicky/modern-errors/README.md#plugin-options). |
| 12 | + * URI identifying and documenting the error class. |
| 13 | + * Ideally, each error class should set one. |
8 | 14 | * |
9 | 15 | * @default undefined |
10 | 16 | */ |
@@ -65,22 +71,24 @@ export interface HttpResponse extends Options { |
65 | 71 | } |
66 | 72 |
|
67 | 73 | /** |
68 | | - * Converts `error` to a plain object to use in an HTTP response. |
69 | | - * Its shape follows [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) |
70 | | - * ("problem details"). |
| 74 | + * Converts `error` to a plain object |
| 75 | + * ([RFC 7807](https://www.rfc-editor.org/rfc/rfc7807), "problem details") to |
| 76 | + * use in an HTTP response. |
| 77 | + * |
| 78 | + * `error` should be an `Error` instance, but invalid errors are automatically |
| 79 | + * [normalized](https://github.com/ehmicky/normalize-exception). |
71 | 80 | * |
72 | 81 | * @example |
73 | 82 | * ```js |
74 | | - * const object = BaseError.httpResponse(error) |
| 83 | + * const error = new AuthError('Could not authenticate.') |
| 84 | + * error.userId = 62 |
| 85 | + * const object = errorHttpResponse(error) |
75 | 86 | * // { |
76 | | - * // type: 'https://example.com/probs/auth', |
77 | | - * // status: 401, |
78 | 87 | * // title: 'AuthError', |
79 | 88 | * // detail: 'Could not authenticate.', |
80 | | - * // instance: '/users/62', |
81 | 89 | * // stack: `AuthError: Could not authenticate. |
82 | 90 | * // at ...`, |
83 | | - * // extra: { userId: 62 }, |
| 91 | + * // extra: { userId: 62 } |
84 | 92 | * // } |
85 | 93 | * ``` |
86 | 94 | */ |
|
0 commit comments