Skip to content

Commit

Permalink
feat (#3) : 예외 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
daehwan2yo committed Apr 10, 2022
1 parent 0c531a8 commit 26dbf52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codingwasabi.howtodo.error;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ControllerExceptionHandler {
@ExceptionHandler({IllegalArgumentException.class, IllegalStateException.class})
public ResponseEntity<String> handleIllegalException(RuntimeException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ public GetCommentsByUserIdResponse getCommentsByUserId(@PathVariable("accountId"
}

@PostMapping("/calendar/{accountId}/result/comments/{targetDate}")
public ResponseEntity<String> createComments(@LoginAccount Account account,
public ResponseEntity<Void> createComments(@LoginAccount Account account,
@PathVariable("accountId") Long accountId,
@PathVariable("targetDate") @DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDate date,
@RequestBody CreateCommentsRequest createCommentsRequest) {
if (account.isAnonymous()) {
return ResponseEntity.badRequest()
.body("need authenticate before write comment");
throw new IllegalStateException("need authenticate before write comment");
}

Comment comment = Comment.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class ExamController {

@GetMapping("/my/exams")
public GetMyExamResponse getMyExam(@LoginAccount Account account) {

if(account.isAnonymous()) {
throw new IllegalStateException("need authenticate before retrieve my exam");
}
return new GetMyExamResponse(examService.getMyExam(account)
.stream()
.map(ExamResponse::new)
Expand Down

0 comments on commit 26dbf52

Please sign in to comment.