How to use the ImATeapot function from http-errors
Find comprehensive JavaScript http-errors.ImATeapot code examples handpicked from public code repositorys.
87 88 89 90 91 92 93 94 95 96
expectationFailed: function expectationFailed (message) { return new createError.ExpectationFailed(message) }, imateapot: function imateapot (message) { return new createError.ImATeapot(message) }, misdirectedRequest: function misdirectedRequest (message) { return new createError.MisdirectedRequest(message)
30
340
17
+ 55 other calls in file
165 166 167 168 169 170 171 172 173
Building fancy errors is made much easier by libraries such as [`boom`](https://www.npmjs.com/package/boom) and [`http-errors`](https://www.npmjs.com/package/http-errors), and `paperplane` can recognize and properly format errors generated by both. So the handler below will respond with a similarly silly message: ```js const { ImATeapot } = require('http-errors') const app = req => { throw new ImATeapot() } ``` Validation is a common source of errors, and [`joi`](https://www.npmjs.com/package/joi) is a library commonly used for validation. To keep things simple, `paperplane` recognizes and properly formats errors generated by `joi`.
10
131
57
158 159 160 161 162 163 164 165 166 167
module.exports.PayloadTooLarge = new HTTPErrors.PayloadTooLarge() module.exports.URITooLong = new HTTPErrors.URITooLong() module.exports.UnsupportedMediaType = new HTTPErrors.UnsupportedMediaType() module.exports.RangeNotSatisfiable = new HTTPErrors.RangeNotSatisfiable() module.exports.ExpectationFailed = new HTTPErrors.ExpectationFailed() module.exports.ImATeapot = new HTTPErrors.ImATeapot() module.exports.MisdirectedRequest = new HTTPErrors.MisdirectedRequest() module.exports.UnprocessableEntity = new HTTPErrors.UnprocessableEntity() module.exports.Locked = new HTTPErrors.Locked() module.exports.FailedDependency = new HTTPErrors.FailedDependency()
1
0
7
+ 41 other calls in file
121 122 123 124 125 126 127 128 129 130
case 417: { httpError = createError.ExpectationFailed(); break; } case 418: { httpError = createError.ImATeapot(); break; } case 421: { httpError = createError.MisdirectedRequest();
0
0
2
+ 41 other calls in file
http-errors.NotFound is the most popular function in http-errors (1819 examples)