-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalExceptionHandler.java
More file actions
51 lines (39 loc) · 1.83 KB
/
GlobalExceptionHandler.java
File metadata and controls
51 lines (39 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.gaethering.modulemember.exception.handler;
import com.gaethering.modulecore.exception.ErrorResponse;
import com.gaethering.modulemember.exception.errorcode.MemberErrorCode;
import com.gaethering.modulemember.exception.member.MemberException;
import com.gaethering.modulemember.exception.pet.PetException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.MailSendException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(MemberException.class)
public ResponseEntity<ErrorResponse> handleMemberException(MemberException e) {
ErrorResponse response = ErrorResponse.builder()
.code(e.getErrorCode().getCode())
.message(e.getMessage())
.build();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(MailSendException.class)
public ResponseEntity<ErrorResponse> handleMailSendException(MailSendException e) {
ErrorResponse response = ErrorResponse.builder()
.code(MemberErrorCode.FAILED_SEND_EMAIL.getCode())
.message(MemberErrorCode.FAILED_SEND_EMAIL.getMessage())
.build();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(PetException.class)
public ResponseEntity<ErrorResponse> handlePetException(PetException e) {
ErrorResponse response = ErrorResponse.builder()
.code(e.getErrorCode().getCode())
.message(e.getMessage())
.build();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
}