Skip to content

Commit 332ef45

Browse files
liubao68yhs0092
authored andcommitted
[SCB-1525]print codec error stack (#1349)
* [SCB-1525]print codec error stack
1 parent 06b7cb8 commit 332ef45

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestConst.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ private RestConst() {
7272
public static final String UPLOAD_FILE_SIZE_THRESHOLD = "servicecomb.uploads.fileSizeThreshold";
7373

7474
public static final String PROVIDER_SCAN_REST_CONTROLLER = "servicecomb.provider.rest.scanRestController";
75+
76+
public static final String PRINT_CODEC_ERROR_MESSGAGE = "servicecomb.codec.printErrorMessage";
7577
}

common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
import javax.servlet.http.HttpServletRequest;
2323
import javax.ws.rs.core.Response.Status;
2424

25+
import org.apache.servicecomb.common.rest.RestConst;
2526
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
2627
import org.apache.servicecomb.common.rest.definition.RestParam;
2728
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

32+
import com.netflix.config.DynamicPropertyFactory;
33+
3134
public final class RestCodec {
3235
private static final Logger LOG = LoggerFactory.getLogger(RestCodec.class);
3336

@@ -61,12 +64,19 @@ public static Object[] restToArgs(HttpServletRequest request,
6164
try {
6265
paramValues[idx] = param.getParamProcessor().getValue(request);
6366
} catch (Exception e) {
64-
// Avoid information leak of user input.
65-
throw new InvocationException(Status.BAD_REQUEST,
66-
String.format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
67-
restOperation.getOperationMeta().getMicroserviceQualifiedName(),
68-
param.getParamName(),
69-
param.getParamProcessor().getProcessorType()));
67+
// Avoid information leak of user input, and add option for debug use.
68+
String message = String.format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
69+
restOperation.getOperationMeta().getMicroserviceQualifiedName(),
70+
param.getParamName(),
71+
param.getParamProcessor().getProcessorType());
72+
if (DynamicPropertyFactory.getInstance().getBooleanProperty(
73+
RestConst.PRINT_CODEC_ERROR_MESSGAGE, false).get()) {
74+
LOG.error(message, e);
75+
throw new InvocationException(Status.BAD_REQUEST.getStatusCode(), "", message, e);
76+
} else {
77+
LOG.error("{} Add {}=true to print the details.", message, RestConst.PRINT_CODEC_ERROR_MESSGAGE);
78+
throw new InvocationException(Status.BAD_REQUEST, message);
79+
}
7080
}
7181
}
7282

swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ public void doCompletableFutureInvoke(SwaggerInvocation invocation, AsyncRespons
152152
asyncResp.handle(processException(invocation, ex));
153153
});
154154
} catch (IllegalArgumentException ae) {
155+
LOGGER.error("Parameters not valid or types not match {},",
156+
invocation.getInvocationQualifiedName(), ae);
155157
invocation.onBusinessMethodFinish();
156158
invocation.onBusinessFinish();
157159
asyncResp.handle(processException(invocation,
158160
new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
159161
new CommonExceptionData("Parameters not valid or types not match."), ae)));
160-
LOGGER.error("Parameters not valid or types not match {}, "
161-
+ "debug this line to find the actual decode errors.",
162-
invocation.getInvocationQualifiedName());
163162
} catch (Throwable e) {
163+
LOGGER.error("unexpected error {},",
164+
invocation.getInvocationQualifiedName(), e);
164165
invocation.onBusinessMethodFinish();
165166
invocation.onBusinessFinish();
166167
asyncResp.handle(processException(invocation, e));
@@ -190,16 +191,17 @@ public Response doInvoke(SwaggerInvocation invocation) {
190191
invocation.onBusinessMethodFinish();
191192
invocation.onBusinessFinish();
192193
} catch (IllegalArgumentException ae) {
194+
LOGGER.error("Parameters not valid or types not match {},",
195+
invocation.getInvocationQualifiedName(), ae);
193196
invocation.onBusinessMethodFinish();
194197
invocation.onBusinessFinish();
195198
// ae.getMessage() is always null. Give a custom error message.
196199
response = processException(invocation,
197200
new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
198201
new CommonExceptionData("Parameters not valid or types not match."), ae));
199-
LOGGER.error("Parameters not valid or types not match {}, "
200-
+ "debug this line to find the actual decode errors.",
201-
invocation.getInvocationQualifiedName());
202202
} catch (Throwable e) {
203+
LOGGER.error("unexpected error {},",
204+
invocation.getInvocationQualifiedName(), e);
203205
invocation.onBusinessMethodFinish();
204206
invocation.onBusinessFinish();
205207
response = processException(invocation, e);

0 commit comments

Comments
 (0)