@curveball/http-errors
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,9 @@ | ||
0.2.0 (2018-09-12) | ||
================== | ||
* Added `Unauthorized`, `PaymentRequired`, `Forbidden`. | ||
* Added support for `WWW-Authenticate` header for 401 responses and `Allow` | ||
for 405 responses. | ||
0.1.0 (2018-09-11) | ||
@@ -2,0 +10,0 @@ ================== |
@@ -21,2 +21,37 @@ export interface HttpError extends Error { | ||
} | ||
declare type WwwAuthenticate = string | string[]; | ||
/** | ||
* Emits a 401 Unauthorized. | ||
* | ||
* This response must come with a WWW-Authenticate header. This challenge can | ||
* optionally be provided via the constructor. | ||
* | ||
* examples: | ||
* new Unauthorized('Login failed', 'Basic'); | ||
* new Unauthorized('Login failed', 'Basic; realm="secret area"'); | ||
* new Unauthorized('Login failed', ['Basic; realm="secret area', 'Bearer']); | ||
*/ | ||
export declare class Unauthorized extends HttpErrorBase { | ||
httpCode: number; | ||
title: string; | ||
wwwAuthenticate: WwwAuthenticate; | ||
constructor(detail?: string | null, wwwAuthenticate?: WwwAuthenticate); | ||
} | ||
/** | ||
* Emits 402 Payment Required | ||
*/ | ||
export declare class PaymentRequired extends HttpErrorBase { | ||
httpCode: number; | ||
title: string; | ||
} | ||
/** | ||
* Emits 403 Forbidden | ||
*/ | ||
export declare class Forbidden extends HttpErrorBase { | ||
httpCode: number; | ||
title: string; | ||
} | ||
/** | ||
* Emits 404 Not Found | ||
*/ | ||
export declare class NotFound extends HttpErrorBase { | ||
@@ -26,6 +61,20 @@ httpCode: number; | ||
} | ||
/** | ||
* Emits 405 Method Not Allowed. | ||
* | ||
* The 405 Method Not Allowed HTTP response requires an Allow header. | ||
* You can optionally use the second argument to provide this. | ||
* | ||
* Example: | ||
* new MethodNotAllowed('This resource is read-only', ['GET', 'HEAD', 'OPTIONS']); | ||
*/ | ||
export declare class MethodNotAllowed extends HttpErrorBase { | ||
httpCode: number; | ||
title: string; | ||
allow: string[]; | ||
constructor(detail: string | null, allow: string[]); | ||
} | ||
/** | ||
* Emits 500 Internal Server Error | ||
*/ | ||
export declare class InternalServerError extends HttpErrorBase { | ||
@@ -35,2 +84,5 @@ httpCode: number; | ||
} | ||
/** | ||
* Emits 501 Not Implemented | ||
*/ | ||
export declare class NotImplemented extends HttpErrorBase { | ||
@@ -40,1 +92,2 @@ httpCode: number; | ||
} | ||
export {}; |
@@ -36,2 +36,47 @@ "use strict"; | ||
exports.BadRequest = BadRequest; | ||
/** | ||
* Emits a 401 Unauthorized. | ||
* | ||
* This response must come with a WWW-Authenticate header. This challenge can | ||
* optionally be provided via the constructor. | ||
* | ||
* examples: | ||
* new Unauthorized('Login failed', 'Basic'); | ||
* new Unauthorized('Login failed', 'Basic; realm="secret area"'); | ||
* new Unauthorized('Login failed', ['Basic; realm="secret area', 'Bearer']); | ||
*/ | ||
class Unauthorized extends HttpErrorBase { | ||
constructor(detail = null, wwwAuthenticate) { | ||
super(detail); | ||
this.httpCode = 401; | ||
this.title = 'Unauthorized'; | ||
this.wwwAuthenticate = wwwAuthenticate; | ||
} | ||
} | ||
exports.Unauthorized = Unauthorized; | ||
/** | ||
* Emits 402 Payment Required | ||
*/ | ||
class PaymentRequired extends HttpErrorBase { | ||
constructor() { | ||
super(...arguments); | ||
this.httpCode = 402; | ||
this.title = 'Payment Required'; | ||
} | ||
} | ||
exports.PaymentRequired = PaymentRequired; | ||
/** | ||
* Emits 403 Forbidden | ||
*/ | ||
class Forbidden extends HttpErrorBase { | ||
constructor() { | ||
super(...arguments); | ||
this.httpCode = 403; | ||
this.title = 'Forbiddden'; | ||
} | ||
} | ||
exports.Forbidden = Forbidden; | ||
/** | ||
* Emits 404 Not Found | ||
*/ | ||
class NotFound extends HttpErrorBase { | ||
@@ -45,10 +90,23 @@ constructor() { | ||
exports.NotFound = NotFound; | ||
/** | ||
* Emits 405 Method Not Allowed. | ||
* | ||
* The 405 Method Not Allowed HTTP response requires an Allow header. | ||
* You can optionally use the second argument to provide this. | ||
* | ||
* Example: | ||
* new MethodNotAllowed('This resource is read-only', ['GET', 'HEAD', 'OPTIONS']); | ||
*/ | ||
class MethodNotAllowed extends HttpErrorBase { | ||
constructor() { | ||
super(...arguments); | ||
constructor(detail = null, allow) { | ||
super(detail); | ||
this.httpCode = 405; | ||
this.title = 'Method Not Allowed'; | ||
this.allow = allow; | ||
} | ||
} | ||
exports.MethodNotAllowed = MethodNotAllowed; | ||
/** | ||
* Emits 500 Internal Server Error | ||
*/ | ||
class InternalServerError extends HttpErrorBase { | ||
@@ -62,2 +120,5 @@ constructor() { | ||
exports.InternalServerError = InternalServerError; | ||
/** | ||
* Emits 501 Not Implemented | ||
*/ | ||
class NotImplemented extends HttpErrorBase { | ||
@@ -64,0 +125,0 @@ constructor() { |
{ | ||
"name": "@curveball/http-errors", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A standard package for HTTP exceptions", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
11292
217