SWM-99-degree / jariBean

SWM 14th JariBean Project
0 stars 1 forks source link

[BUG] 카페 상세정보를 요청받을 수 없는 오류 #203

Open LineNo2 opened 1 year ago

LineNo2 commented 1 year ago

✏️ 설명

카페의 id를 활용해 카페 상세 정보를 요청받으려고 하면, 500 Internal Server Error가 발생한다.

🌌 발생 Controller

🧾 상황 재현

카페의 상세정보를 요청한다

💻 결과

{
    "timestamp": "2023-10-14T15:14:34.471+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/api/cafe/64fd48821a11b172e165f2fd"
}
2023-10-14 15:14:34.457 DEBUG 1 --- [nio-8080-exec-1] o.s.data.mongodb.core.MongoTemplate      : findOne using query: { "id" : "64fd48821a11b172e165f2fd"} fields: Document{{}} for class: class com.example.jariBean.entity.Cafe in collection: cafe
2023-10-14 15:14:34.459 DEBUG 1 --- [nio-8080-exec-1] o.s.data.mongodb.core.MongoTemplate      : find using query: { "cafeId" : "64fd48821a11b172e165f2fd"} fields: Document{{}} for class: class com.example.jariBean.entity.Table in collection: table
2023-10-14 15:14:34.463 DEBUG 1 --- [nio-8080-exec-1] o.s.data.mongodb.core.MongoTemplate      : Executing aggregation: [{ "$match" : { "startTime" : { "$gte" : { "$date" : "2023-10-14T00:00:00Z"}, "$lte" : { "$date" : "2023-10-14T23:59:59.999Z"}}, "cafe._id" : { "$oid" : "64fd48821a11b172e165f2fd"}}}] in collection reserved
2023-10-14 15:14:34.468 ERROR 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException: Cannot invoke "java.time.LocalDateTime.withDayOfMonth(int)" because the return value of "com.example.jariBean.entity.Cafe.getStartTime()" is null] with root cause

java.lang.NullPointerException: Cannot invoke "java.time.LocalDateTime.withDayOfMonth(int)" because the return value of "com.example.jariBean.entity.Cafe.getStartTime()" is null
    at com.example.jariBean.service.CafeService.fillReservedOnDto(CafeService.java:118) ~[classes!/:na]
    at com.example.jariBean.service.CafeService.getCafeWithTodayReserved(CafeService.java:100) ~[classes!/:na]
    at com.example.jariBean.controller.CafeController.moreInfo(CafeController.java:61) ~[classes!/:na]
    at com.example.jariBean.controller.CafeController$$FastClassBySpringCGLIB$$c8d2bfec.invoke(<generated>) ~[classes!/:na]
psy-choi commented 1 year ago
  1. NullPointer에 대한 오류 예외처리 추가 @ExceptionHandler(NullPointerException.class) public ResponseEntity nullException(NullPointerException e) { log.error(e.getMessage()); return new ResponseEntity<>(new ResponseDto<>(-1, e.getMessage(), "해당 되는 데이터가 없습니다. 다른 요청을 진행해주세요."), HttpStatus.BAD_REQUEST); }

  2. MongoDB 내부의 validation 추가