我有一个控制器类
测试控制器.java
@RequestMapping(value = "/{entityType}/values/timeseries", method = RequestMethod.GET, params = {...})
@ResponseBody
public DeferredResult<ResponseEntity> getGroupTimeseries(...) Boolean useStrictDataTypes) throws ThingsboardException {
try {
Futures.addCallback(tsService.findAll(tenantId, entityId, queries), new FutureCallback<List<TsKvEntry>>() {
public void onSuccess(List<TsKvEntry> result) {
Map<String, Object> volumeMap = fixedFlowRateAlgorithm(result, keys);
// Additional processing
}
public void onFailure(Throwable thrown) {
log.error("getGroupTimeseries" + thrown);
deferredResult.setErrorResult(thrown);
}
}, MoreExecutors.directExecutor());
return deferredResult;
} catch (Exception error) {
throw handleException(error);
}
}
还有另一个静态方法
public static Map<String, Object> fixedFlowRateCalculate(...) {
// No Side effect, pure method here
// just calculation
return results;
}
当我向此 API 端点发送请求时,运行一段时间后返回此错误
{
"status": 500,
"message": "Request timeout",
"errorCode": 2,
"timestamp": "2024-05-10T17:10:08.978+00:00"
}
但是,当我使用调试器跟踪问题时,错误实际上是
ERROR c.g.c.util.concurrent.AbstractFuture - RuntimeException while executing runnable CallbackListener{org.thingsboard.server.controller.TestController$1@669c92f8} with executor MoreExecutors.directExecutor()
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "volume" (class org.thingsboard.server.data.SensorData), not marked as ignorable
为什么我无法获得 api 调用的错误响应? 怎么解决?
我期待收到一条错误消息,指示
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“卷”(org.thingsboard.server.data.SensorData 类),未标记为可忽略
通常,您不应该告诉客户端服务器上发生了 HTTP 500 错误的情况。这是违反安全的。如果您想知道发生了什么,请发送状态 200 并将错误消息添加到有效负载