Replies: 1 comment
-
error로 수합되는 정보들은 logger로 기록 할 계획입니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
9/20 1130i경 @phjppo0918님께서 건의하신 방안입니다.
현준님이 작성하신 코드입니다.
제가 작성한 코드입니다.
현준님이 작성하신 코드의 리턴값은 크게 두 종류입니다.
true
또는new Error()
제가 작성한 코드의 리턴값은 세 종류입니다.
true
,false
그리고MongoError
위 두 코드의 리턴 값은 한 종류가 더 늘은 것 뿐이지만, 외부에서 볼 때 new Error()는 어떤 에러가 던져질지 예측이 불가능합니다.
하지만 MongoError의 경우 MongoServer에서 발생한 에러라는 것을 유추 가능합니다.
이는 ErrorHandler입장에서 보면 더 명확합니다.
모든 에러는 결국 ErrorHandler로 던져집니다.
현재 ErrorHandler의 코드입니다.
만약 현준님의 방식대로 Error를 Throw하게 된다면.
이런식으로 코드가 짜여집니다.
물론 현재야 관리할 에러가 두 종류밖에 없지만 나중에 uri의 깊이가 깊어질 때를 가정해 봅시다.
client에서 서랍안의 문서안의 카드를 요청합니다.
{{HOST}}/cabinet/{{cabinet_id}}/document/{{document_id}}/card/{{card_id}}
이 경우에 cabinet이 없다면
throw new Error('no cabinet')
,document가 없다면
throw new Error('no document')
,card가 없다면
throw new Error('no card')
를 해야하고 ErrorHandler에서도 이런 정보에 대해 일일이 처리해야합니다.때문에 미리 이러한 종류의 에러를 정의해놓고
NotFoundError('no document')
를 하게된다면, ErrorHandler에서는 한 줄로 처리할 수 있습니다.또한 Service는 DB의 대리인이고 Service까지만 떼어서 다른 app에서 응용할 수 있어야 됨을 제가 말씀드렸습니다.
이 경우에 service는 mongodb에 종속되어 있는, Model과 Service를 묶어 하나의 모듈이라고 생각할 수 있습니다.
이 때에도 service는 mongoerror만 throw하는게 맞다고 생각합니다.
다음은 code를 실생활에서 적용하여 설명한 예제들입니다.
이 때, 병은 간부에게 세가지 종류의 대답이 가능합니다.
true
false
error
true
false
error
다음은 사회에서 회사에 다니다가 늦은나이에 입대한 후임의 의견입니다.
true
false
error
제가 생각하는 error는 이렇게 사용할 때 더 명확하다고 생각합니다.
매번 제 의견대로 가게되어 죄송하지만, 초반인 만큼 구조를 잘 잡아놔야하고
오픈소스 해커톤인 만큼 2차 가공자가 코드를 응용한다를 생각하면 (Model, Service) (Controller, Router) 이렇게 두 부류로 나뉘는게 맞는 것 같습니다.
Beta Was this translation helpful? Give feedback.
All reactions