Skip to content

Commit

Permalink
📝 Added missing jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecarr committed Nov 17, 2021
1 parent 06ed90d commit 137fbbc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
import type { ServerResponse } from 'http'

/**
* An RFC 7807 compliant error.
*/
export type Error = {
/**
* A URI reference that identifies the problem type.
*/
type: string
/**
* A short, human-readable summary of the problem type.
*
* This should not change between occurrences of the same problem type,
* except for purposes of localization.
*/
title: string
/**
* The HTTP status code for this ocurrence of the problem type.
*/
status: number
/**
* A human-readable explanation specific to this ocurrence of the
* problem type.
*/
detail: string
/**
* A URI reference that identifies the specific occurrence of the problem
* type.
*/
instance: string
};

/**
* The MIME/media type for RFC 7807 error responses (in JSON).
*/
export const mime = 'application/problem+json'

/**
* Generates an RFC 7807 compliant error and sends it as an HTTP response.
*
* @param res The `http.ServerResponse` object to send the error to.
* @param err The error details to send.
*/
export function withError (res: ServerResponse, err: Partial<Error>): void {
if (typeof err.status !== 'undefined') {
res.statusCode = err.status
Expand Down

0 comments on commit 137fbbc

Please sign in to comment.