Created
June 27, 2018 18:29
-
-
Save sandeepsuvit/2486c99c0346db87de24539472f34451 to your computer and use it in GitHub Desktop.
Type definitions for express-boom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Type definitions for express-boom | |
* Definitions by: Sandeep K Nair <https://github.com/sandeepsuvit> | |
* @author: Sandeep K Nair | |
*/ | |
declare namespace Express { | |
interface Boom { | |
// Add boom's properties in here | |
wrap: (error: Error, statusCode?: number, message?: string) => BoomError; | |
create: (statusCode: number, message?: string, data?: any) => BoomError; | |
// 4xx | |
badRequest: (message?: string, data?: any) => BoomError; | |
unauthorized: (message?: string, scheme?: any, attributes?: any) => BoomError; | |
forbidden: (message?: string, data?: any) => BoomError; | |
notFound: (message?: string, data?: any) => BoomError; | |
methodNotAllowed: (message?: string, data?: any) => BoomError; | |
notAcceptable: (message?: string, data?: any) => BoomError; | |
proxyAuthRequired: (message?: string, data?: any) => BoomError; | |
clientTimeout: (message?: string, data?: any) => BoomError; | |
conflict: (message?: string, data?: any) => BoomError; | |
resourceGone: (message?: string, data?: any) => BoomError; | |
lengthRequired: (message?: string, data?: any) => BoomError; | |
preconditionFailed: (message?: string, data?: any) => BoomError; | |
entityTooLarge: (message?: string, data?: any) => BoomError; | |
uriTooLong: (message?: string, data?: any) => BoomError; | |
unsupportedMediaType: (message?: string, data?: any) => BoomError; | |
rangeNotSatisfiable: (message?: string, data?: any) => BoomError; | |
expectationFailed: (message?: string, data?: any) => BoomError; | |
badData: (message?: string, data?: any) => BoomError; | |
tooManyRequests: (message?: string, data?: any) => BoomError; | |
// 5xx | |
notImplemented: (message?: string, data?: any) => BoomError; | |
badGateway: (message?: string, data?: any) => BoomError; | |
serverTimeout: (message?: string, data?: any) => BoomError; | |
gatewayTimeout: (message?: string, data?: any) => BoomError; | |
badImplementation: (message?: string, data?: any) => BoomError; | |
} | |
export interface BoomError { | |
data: any; | |
reformat: () => void; | |
isBoom: boolean; | |
isServer: boolean; | |
message: string; | |
output: Output; | |
} | |
export interface Output { | |
statusCode: number; | |
headers: any; | |
payload: any; | |
} | |
export interface Response { | |
boom: Boom | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function someMiddleware(req: express.Request, res: express.Response, next: express.NextFunction) { | |
// use it this way | |
res.boom.forbidden("Failed to grant access to resource."); | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment