2
Sails.js을 사용하여 REST API 서버를 개발하고 있습니다. 사용의 편의를 위해 Sails.js의 예외 처리
는 추상화 위해 나는 나의 컨트롤러의 내부 예외를 던지고 싶습니다 예 :// api/controllers/TempController.js
module.exports = {
index: function(request, response) {
throw new NotFoundException('Specific user is not found.');
throw new AccessDeniedException('You have no permissions to access this resource.');
throw new SomeOtherException('Something went wrong.');
}
};
나는 (글로벌 수준에) 자동으로 그 예외를 포착하고로 변환하려면 어떻게 유효한 JSON 응답? 예컨대 :
가 내장 사용하는 등의 예외를 처리하기 위해serverError
응답 최선의 방법
{
"success": false,
"exception": {
"type": "NotFoundException",
"message": "Specific user is not found."
}
}
인가? 또는 사용자 지정 미들웨어를 만드는 것이 더 좋습니까? 그렇다면 간단한 예제를 제공 할 수 있습니까?