Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.week2.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -19,4 +20,18 @@ public String handleInternalError() {
log.error("InternalError 처리 시작");
return "InternalError 핸들링";
}

@ExceptionHandler(CustomException.class)
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
log.error("커스텀 에러 발생: {}", e.getMessage(), e);

ErrorCode errorCode = e.getErrorCode();

ErrorResponse errorResponse = ErrorResponse.builder()
.errorCode(errorCode)
.errorMessage(e.getMessage())
.build();

return ResponseEntity.status(errorCode.getStatus()).body(errorResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MainController {

@GetMapping("/main")
public String mainMethod(@RequestParam String str) {
public String mainMethod(@RequestParam("str") String str) {
return str;
}

Expand Down