Skip to content

Commit d7c0a78

Browse files
committed
Fix types documentation
1 parent 24f45e1 commit d7c0a78

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

types/main.d.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/**
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.
39
*/
410
export interface Options {
511
/**
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.
814
*
915
* @default undefined
1016
*/
@@ -65,22 +71,24 @@ export interface HttpResponse extends Options {
6571
}
6672

6773
/**
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).
7180
*
7281
* @example
7382
* ```js
74-
* const object = BaseError.httpResponse(error)
83+
* const error = new AuthError('Could not authenticate.')
84+
* error.userId = 62
85+
* const object = errorHttpResponse(error)
7586
* // {
76-
* // type: 'https://example.com/probs/auth',
77-
* // status: 401,
7887
* // title: 'AuthError',
7988
* // detail: 'Could not authenticate.',
80-
* // instance: '/users/62',
8189
* // stack: `AuthError: Could not authenticate.
8290
* // at ...`,
83-
* // extra: { userId: 62 },
91+
* // extra: { userId: 62 }
8492
* // }
8593
* ```
8694
*/

0 commit comments

Comments
 (0)