exception : spring - ResponseStatusExceptionResolver
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package hello.exception.api;
|
||||
|
||||
import hello.exception.exception.BadRequestException;
|
||||
import hello.exception.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
|
||||
@@ -27,6 +30,16 @@ public class ApiExceptionController {
|
||||
|
||||
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
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package hello.exception.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "error.bad")
|
||||
public class BadRequestException extends RuntimeException{
|
||||
}
|
||||
@@ -6,6 +6,6 @@ server.error.whitelabel.enabled=true
|
||||
# always :항상 사용
|
||||
# on_param : 파라미터가 있을 때 사용
|
||||
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
exception/src/main/resources/messages.properties
Normal file
1
exception/src/main/resources/messages.properties
Normal file
@@ -0,0 +1 @@
|
||||
error.bad=잘못된 요청 오류 입니다.
|
||||
Reference in New Issue
Block a user