How to use the MethodNotAllowed function from http-errors
Find comprehensive JavaScript http-errors.MethodNotAllowed code examples handpicked from public code repositorys.
49 50 51 52 53 54 55 56 57
} } break; default: response.set('allow', 'GET,POST'); next(new httpError.MethodNotAllowed()); break; } }
51
418
30
+ 7 other calls in file
35 36 37 38 39 40 41 42 43 44
notFound: function notFound (message) { return new createError.NotFound(message) }, methodNotAllowed: function methodNotAllowed (message) { return new createError.MethodNotAllowed(message) }, notAcceptable: function notAcceptable (message) { return new createError.NotAcceptable(message)
30
340
17
+ 55 other calls in file
GitHub: eggjs/egg-router
276 277 278 279 280 281 282 283 284 285
if (options.throw) { let notAllowedThrowable; if (typeof options.methodNotAllowed === 'function') { notAllowedThrowable = options.methodNotAllowed(); // set whatever the user returns from their function } else { notAllowedThrowable = new HttpError.MethodNotAllowed(); } throw notAllowedThrowable; } else { ctx.status = 405;
9
49
0
50 51 52 53 54 55 56 57 58 59 60 61
} // Renew JWT Token when is going to be expired function renew(token, expire) { if (!token) throw Error.UnprocessableEntity('Token is undefined.') if (!config.jwt.allow_renew) throw Error.MethodNotAllowed('Renewing tokens is not allowed.') const decoded = Jwt.decode(token) if (!decoded.exp) return token if (decoded.exp - Math.floor(Date.now() / 1000) > config.jwt.renew_threshold) return token
1
3
0
145 146 147 148 149 150 151 152 153 154
/* Generic errors */ module.exports.BadRequest = new HTTPErrors.BadRequest() module.exports.Unauthorized = new HTTPErrors.Unauthorized() module.exports.Forbidden = new HTTPErrors.Forbidden() module.exports.NotFound = new HTTPErrors.NotFound() module.exports.MethodNotAllowed = new HTTPErrors.MethodNotAllowed() module.exports.NotAcceptable = new HTTPErrors.NotAcceptable() module.exports.ProxyAuthenticationRequired = new HTTPErrors.ProxyAuthenticationRequired() module.exports.RequestTimeout = new HTTPErrors.RequestTimeout() module.exports.Conflict = new HTTPErrors.Conflict()
1
0
7
+ 41 other calls in file
394 395 396 397 398 399 400 401 402 403
} else if (!allowed[ctx.method]) { if (options.throw) { const notAllowedThrowable = typeof options.methodNotAllowed === "function" ? options.methodNotAllowed() // set whatever the user returns from their function : new HttpError.MethodNotAllowed(); throw notAllowedThrowable; } else { ctx.status = 405;
0
2
0
GitHub: toanhhg123/travle_Tien
22 23 24 25 26 27 28 29 30 31
bookSchema.pre("save", async function (next) { try { const checkIn = this.checkIn; const checkOut = this.checkOut; if (checkIn > checkOut) throw createHttpError.MethodNotAllowed("check in and checkout illegal"); const booking = await this.constructor .findOne({ roomId: this.roomId }) .populate("userId") .populate("roomId")
0
0
0
+ 3 other calls in file
106 107 108 109 110 111 112 113 114 115
continue; } if (endpoint._methods.indexOf(method) === -1) { error = Object.assign( new httperr.MethodNotAllowed(), {methods: endpoint._methods} ); continue; }
0
0
0
368 369 370 371 372 373 374 375 376 377
ctx.status = 200; ctx.body = ''; ctx.set("Allow", allowedArr.join(", ")); } else if (!allowed[ctx.method]) { if (options.throw) { throw typeof options.methodNotAllowed === "function" ? options.methodNotAllowed() : new HttpError.MethodNotAllowed(); } else { ctx.status = 405; ctx.set("Allow", allowedArr.join(", ")); }
0
0
0
69 70 71 72 73 74 75 76 77 78
case 404: { httpError = createError.NotFound(); break; } case 405: { httpError = createError.MethodNotAllowed(); break; } case 406: { httpError = createError.NotAcceptable();
0
0
2
+ 41 other calls in file
http-errors.NotFound is the most popular function in http-errors (1819 examples)