Skip to content

Commit ac8c8a5

Browse files
[CSAPI]: Preserve exception cause on invalid payload
For some exceptions, the cause backtrace provides necessary details for debugging the actual cause of the issue, since the message is not always detailed enough.
1 parent 9ef776a commit ac8c8a5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sensorhub-service-consys/src/main/java/org/sensorhub/impl/service/consys/resource/BaseResourceHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected void create(final RequestContext ctx) throws IOException
355355
}
356356
catch (ResourceParseException e)
357357
{
358-
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage());
358+
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage(), e);
359359
}
360360
}
361361

@@ -399,7 +399,7 @@ protected void update(final RequestContext ctx, final String id) throws IOExcept
399399
}
400400
catch (ResourceParseException e)
401401
{
402-
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage());
402+
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage(), e);
403403
}
404404

405405
// update in datastore

sensorhub-service-sweapi/src/main/java/org/sensorhub/impl/service/sweapi/ServiceErrors.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ public static InvalidRequestException badRequest(String msg)
4242

4343
public static InvalidRequestException invalidPayload(String msg)
4444
{
45-
return new InvalidRequestException(ErrorCode.BAD_PAYLOAD, msg);
45+
return invalidPayload(msg, null);
46+
}
47+
48+
49+
public static InvalidRequestException invalidPayload(String msg, Throwable cause)
50+
{
51+
return new InvalidRequestException(ErrorCode.BAD_PAYLOAD, msg, cause);
4652
}
4753

4854

0 commit comments

Comments
 (0)