Skip to content

Commit

Permalink
스프링이 제공하는 ExceptionResolver1
Browse files Browse the repository at this point in the history
  • Loading branch information
kiteB committed Oct 4, 2021
1 parent 3cbbf9a commit 9f380e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
@@ -0,0 +1,9 @@
package hello.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

//@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "잘못된 오류 요청")
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "error.bad")
public class BadRequestException extends RuntimeException{
}
@@ -1,12 +1,15 @@
package hello.exception.api;

import hello.exception.BadRequestException;
import hello.exception.UserException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

@Slf4j
@RestController
Expand All @@ -29,6 +32,16 @@ public MemberDto getMember(@PathVariable("id") String id) {
return new MemberDto(id, "hello " + id);
}

@GetMapping("/api/response-status-ex1")
public String responseStatusEx1() {
throw new BadRequestException();
}

@GetMapping("/api/response-status-ex2")
public String responseStatusEx2() {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "error.bad", new IllegalArgumentException());
}

@Data
@AllArgsConstructor
static class MemberDto {
Expand Down
2 changes: 1 addition & 1 deletion exception/src/main/resources/application.properties
@@ -1,6 +1,6 @@
server.error.whitelabel.enabled=false

server.error.include-exception=true
server.error.include-message=on_param
server.error.include-message=always
server.error.include-stacktrace=on_param
server.error.include-binding-errors=on_param
1 change: 1 addition & 0 deletions exception/src/main/resources/messages.properties
@@ -0,0 +1 @@
error.bad=잘못된 오류 요청입니다. 메시지 사용

0 comments on commit 9f380e8

Please sign in to comment.