Skip to content

Commit 1d9e1e2

Browse files
authored
Merge pull request #2 from github/add-invalid-json-exception-handler
Add invalid json exception handler
2 parents ceb289d + b8a18db commit 1d9e1e2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

runtime/spring/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'com.flit'
6-
archivesBaseName = 'flit-undertow-runtime'
6+
archivesBaseName = 'flit-spring-runtime'
77
sourceCompatibility = 1.8
88

99
repositories {

runtime/spring/src/main/java/com/flit/runtime/spring/FlitExceptionHandler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.flit.runtime.ErrorCode;
44
import com.flit.runtime.FlitException;
5+
import com.google.protobuf.InvalidProtocolBufferException;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import org.springframework.http.MediaType;
@@ -40,6 +41,21 @@ public ResponseEntity<?> handleException(HttpServletRequest request, Exception e
4041
.body(response);
4142
}
4243

44+
@ExceptionHandler(InvalidProtocolBufferException.class)
45+
public ResponseEntity<?> handlehandleInvalidProtocolBufferException(HttpServletRequest request, Exception e) {
46+
LOGGER.error("InvalidProtocolBufferException: request = {}, method = {}, msg= {}",
47+
request.getRequestURI(), request.getMethod(), e.getMessage(), e);
48+
49+
Map<String, Object> response = new HashMap<>();
50+
response.put("code", ErrorCode.INVALID_ARGUMENT);
51+
response.put("msg", e.getMessage());
52+
53+
return ResponseEntity
54+
.status(ErrorCode.INVALID_ARGUMENT.getHttpStatus())
55+
.contentType(MediaType.APPLICATION_JSON)
56+
.body(response);
57+
}
58+
4359
@ExceptionHandler(FlitException.class)
4460
public ResponseEntity<?> handleFlitException(HttpServletRequest request, FlitException e) {
4561

0 commit comments

Comments
 (0)