👋

エラー関連

2023/10/21に公開

エラー関連

sailsを使用して500エラーを発生させる

500.ejs

https://sailsjs.com/documentation/anatomy/views/500.ejs

res.serverError()

https://sailsjs.com/documentation/reference/response-res/res-server-error

res.view()

https://sailsjs.com/documentation/reference/response-res/res-view

res.redirect()

https://sailsjs.com/documentation/reference/response-res/res-redirect

結果

500エラーのページに遷移するためにはsails.resが必要。

例外発生時のイベントハンドラ

process.on('uncaughtException', handleErrors);

引数

  • err <Error> : The uncaught exception.
  • origin <string> : Indicates if the exception originates from an unhandled rejection or from a synchronous error. Can either be 'uncaughtException' or 'unhandledRejection'. The latter is used when an exception happens in a Promise based async context (or if a Promise is rejected) and --unhandled-rejections flag set to strict or throw (which is the default) and the rejection is not handled, or when a rejection happens during the command line entry point's ES module static loading phase.

process.on('unhandledRejection', handleErrors);

引数

  • reason <Error> | <any> : The object with which the promise was rejected (typically an Error object).
  • promise <Promise> : The rejected promise.

参考サイト

Discussion