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)
fork icon30
star icon340
watch icon17

+ 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`.
fork icon10
star icon131
watch icon57

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()
fork icon1
star icon0
watch icon7

+ 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();
fork icon0
star icon0
watch icon2

+ 41 other calls in file