2
2
3
3
import com .flit .runtime .ErrorCode ;
4
4
import com .flit .runtime .FlitException ;
5
+ import com .google .protobuf .InvalidProtocolBufferException ;
6
+ import java .util .HashMap ;
7
+ import java .util .Map ;
8
+ import javax .servlet .http .HttpServletRequest ;
5
9
import org .slf4j .Logger ;
6
10
import org .slf4j .LoggerFactory ;
7
11
import org .springframework .http .MediaType ;
11
15
import org .springframework .web .bind .annotation .ExceptionHandler ;
12
16
import org .springframework .web .servlet .mvc .method .annotation .ResponseEntityExceptionHandler ;
13
17
14
- import javax .servlet .http .HttpServletRequest ;
15
- import java .util .HashMap ;
16
- import java .util .Map ;
17
-
18
18
@ ControllerAdvice
19
19
@ Component
20
20
public class FlitExceptionHandler extends ResponseEntityExceptionHandler {
21
21
22
- private static final Logger LOGGER = LoggerFactory .getLogger (FlitExceptionHandler .class );
22
+ private static final Logger LOGGER = LoggerFactory .getLogger (FlitExceptionHandler .class );
23
23
24
24
25
25
@ ExceptionHandler (Exception .class )
@@ -40,6 +40,21 @@ public ResponseEntity<?> handleException(HttpServletRequest request, Exception e
40
40
.body (response );
41
41
}
42
42
43
+ @ ExceptionHandler (InvalidProtocolBufferException .class )
44
+ public ResponseEntity <?> handlehandleInvalidProtocolBufferException (HttpServletRequest request , Exception e ) {
45
+ LOGGER .error ("InvalidProtocolBufferException: request = {}, method = {}, msg= {}" ,
46
+ request .getRequestURI (), request .getMethod (), e .getMessage (), e );
47
+
48
+ Map <String , Object > response = new HashMap <>();
49
+ response .put ("code" , ErrorCode .INVALID_ARGUMENT );
50
+ response .put ("msg" , e .getMessage ());
51
+
52
+ return ResponseEntity
53
+ .status (ErrorCode .INVALID_ARGUMENT .getHttpStatus ())
54
+ .contentType (MediaType .APPLICATION_JSON )
55
+ .body (response );
56
+ }
57
+
43
58
@ ExceptionHandler (FlitException .class )
44
59
public ResponseEntity <?> handleFlitException (HttpServletRequest request , FlitException e ) {
45
60
0 commit comments