Skip to content

Commit 86be6e6

Browse files
committed
Add json format exception
1 parent eec32a3 commit 86be6e6

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

src/main/java/com/longcoding/moon/exceptions/ExceptionType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public enum ExceptionType {
3030
E_1009_SERVICE_RATELIMIT_OVER("1009", HttpStatus.FORBIDDEN),
3131
E_1010_IP_ADDRESS_IS_NOT_PERMITTED("1010", HttpStatus.FORBIDDEN),
3232
E_1011_NOT_SUPPORTED_CONTENT_TYPE("1011", HttpStatus.BAD_REQUEST),
33+
E_1013_MALFORMED_JSON_EXCEPTION("1013", HttpStatus.BAD_REQUEST),
3334

3435
E_1100_SERVICE_QUOTA_IS_NOT_REMAINS("1100", HttpStatus.BAD_GATEWAY),
3536
E_1101_API_GATEWAY_IS_EXHAUSTED("1101", HttpStatus.SERVICE_UNAVAILABLE),

src/main/java/com/longcoding/moon/interceptors/impl/ExtractRequestPathInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.longcoding.moon.interceptors.impl;
22

33
import com.google.common.collect.Maps;
4+
import com.google.gson.JsonIOException;
45
import com.longcoding.moon.exceptions.ExceptionType;
56
import com.longcoding.moon.helpers.*;
67
import com.longcoding.moon.interceptors.AbstractBaseInterceptor;
@@ -61,6 +62,8 @@ public boolean preHandler(HttpServletRequest request, HttpServletResponse respon
6162
requestInfo.setRequestBodyMap(extractedBodyMap);
6263
} else requestInfo.setRequestBodyMap(Maps.newHashMap());
6364
} else requestInfo.setRequestBody(StreamUtils.copyToByteArray(request.getInputStream()));
65+
} catch (JsonIOException ex) {
66+
generateException(ExceptionType.E_1013_MALFORMED_JSON_EXCEPTION);
6467
} catch (Exception ex) {
6568
generateException(ExceptionType.E_1011_NOT_SUPPORTED_CONTENT_TYPE);
6669
}

src/main/java/com/longcoding/moon/services/sync/SyncService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private boolean createOrUpdateApi(SyncType syncType, ApiInfo apiInfo) {
189189
ServiceInfo serviceInfo = apiExposeSpec.getServiceInfoCache().get(apiInfo.getServiceId());
190190

191191
if (Objects.nonNull(serviceInfo)) {
192-
192+
193193
String servicePath = serviceInfo.getServicePath().startsWith("/")? serviceInfo.getServicePath() : "/" + serviceInfo.getServicePath();
194194
Pattern routingUrlInRegex = Pattern.compile(servicePath + routingPathInRegex);
195195

src/main/resources/message/error-message_en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1010: IP Address is not permitted. Please check the IP address.
1212
1011: Unsupported content type or invalid body
1313
1012: Not Supported Content-Type. To use the transform's body_json option, the request body must be applicaiton/json unconditionally.
14+
1013: Body is not a json format.
1415

1516
1100: Internal Server Error. There is no remaining quota.
1617
1101: Internal Server Error. Proxy server is exhausted.

0 commit comments

Comments
 (0)