-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPlayHiveExceptionController.java
More file actions
46 lines (42 loc) · 1.34 KB
/
PlayHiveExceptionController.java
File metadata and controls
46 lines (42 loc) · 1.34 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
package org.myteam.server.global.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class PlayHiveExceptionController {
private final Logger log = LoggerFactory.getLogger(getClass());
@ExceptionHandler(value = PlayHiveException.class)
public ResponseEntity<?> serviceException(PlayHiveException e) {
return ResponseEntity
.status(e.getErrorCode().getStatus())
.body(
new ErrorResponse(
e.getErrorCode().getStatus(),
e.getMessage(),
e.getErrorMap()
)
);
}
/**
* 데이터 제약 조건으로 인한 Exception
**/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BindException.class)
public ResponseEntity<?> BindException(BindException e) {
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(
new ErrorResponse(
HttpStatus.BAD_REQUEST,
e.getBindingResult().getAllErrors().get(0).getDefaultMessage(),
null
)
);
}
}