22
33import com .flit .runtime .ErrorCode ;
44import 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 ;
59import org .slf4j .Logger ;
610import org .slf4j .LoggerFactory ;
711import org .springframework .http .MediaType ;
1115import org .springframework .web .bind .annotation .ExceptionHandler ;
1216import org .springframework .web .servlet .mvc .method .annotation .ResponseEntityExceptionHandler ;
1317
14- import javax .servlet .http .HttpServletRequest ;
15- import java .util .HashMap ;
16- import java .util .Map ;
17-
1818@ ControllerAdvice
1919@ Component
2020public class FlitExceptionHandler extends ResponseEntityExceptionHandler {
2121
22- private static final Logger LOGGER = LoggerFactory .getLogger (FlitExceptionHandler .class );
22+ private static final Logger LOGGER = LoggerFactory .getLogger (FlitExceptionHandler .class );
2323
2424
2525 @ ExceptionHandler (Exception .class )
@@ -40,6 +40,21 @@ public ResponseEntity<?> handleException(HttpServletRequest request, Exception e
4040 .body (response );
4141 }
4242
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+
4358 @ ExceptionHandler (FlitException .class )
4459 public ResponseEntity <?> handleFlitException (HttpServletRequest request , FlitException e ) {
4560
0 commit comments