errorHandle.js 314 B

1234567891011121314
  1. module.exports = () => {
  2. return async (ctx, next) => {
  3. await next().catch((err) => {
  4. if (err.status === 401) {
  5. ctx.status = 401;
  6. ctx.body = {
  7. error: err.originalError ? err.originalError.message : err.message,
  8. };
  9. } else {
  10. throw err;
  11. }
  12. })
  13. }
  14. }