Skip to content

Commit

Permalink
[FEAT] global controller advice and dto
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Sep 27, 2023
1 parent 53561d5 commit 9ddc890
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.twtw.backend.global.advice;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ErrorResponse {
private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.twtw.backend.global.advice;

import com.twtw.backend.global.exception.EntityNotFoundException;
import com.twtw.backend.global.exception.WebClientResponseException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalErrorAdvice {

@ExceptionHandler(WebClientResponseException.class)
public ResponseEntity<ErrorResponse> webClientResponse(final WebClientResponseException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(EntityNotFoundException.class)
public ResponseEntity<ErrorResponse> entityNotFound(final EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.twtw.backend.global.exception;

public class EntityNotFoundException extends IllegalArgumentException {
private static final String MESSAGE = "엔티티를 조회할 수 없습니다.";

public EntityNotFoundException() {
super(MESSAGE);
}
}

0 comments on commit 9ddc890

Please sign in to comment.