Intercepting error handling with loopback

你。 提交于 2019-12-05 22:17:14

I need to "catch" all the messages and translate them

This is the beginning of an answer. You can write an error-handling middleware that will intercept any error returned by the server. You will need in turn to implement the logic for making the translation.

module.exports = function() { 
   return function logError(err, req, res, next) { 
      if (err) {
        console.log('ERR', req.url, err);
      }
      next();
   };
};

This middleware must be configured to be called in the final phase. Save the code above in log-error.js for instance, then modify server/middleware.json

{ "final": { "./middleware/log-error": {} } }

I need a full list of loopback codes/messages

I'm pretty sure there is no such thing. Errors are build and returned all over the place in the code, not centralized anywhere.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!