Skip to content

Commit 5a70843

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 5ca3684 commit 5a70843

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/ServiceErrors.java

Lines changed: 7 additions & 1 deletion
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

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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)