Custom operation invalid JSON response
pavlushkin opened this issue · 11 comments
Question
Hello! I make a custom operation call with invalid JSON and get inconsistent behavior for a client:
Request:
PUT /$load-observations
content-type: application/json
accept: application/json
{"x": NaN}
Actual Aidbox behavior:
- The request is not passed to Aidbox App operation handler.
- No log record registered in Elasticsearch
- Response Status Code: 500
- Response text:
Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow at [Source: (BufferedReader); line: 1, column: 10]
Desired behavior:
- Aidbox proxies the request to Aidbox App operation handler.
- App validates invalid JSON and returns 422
Question:
How can I get desired behavior?
@pavlushkin Please specify the urgency of the request
@pavlushkin so you want your app to parse the json and get the same error, but return as 422, or it would be ok if Aidbox returned 422 in this case instead of 500?
@pavlushkin as a workaround you can change load-observations content type to text/plain, so Aidbox won't parse the json
@pavlushkin so you want your app to parse the json and get the same error, but return as 422, or it would be ok if Aidbox returned 422 in this case instead of 500?
I would like the app parsing JSON. But if Aidbox return 422 and log this unsuccessful attempt to Elastic, that would be fine.
@pavlushkin as a workaround you can change load-observations content type to text/plain, so Aidbox won't parse the json
Now I get 422
{
"resourceType": "OperationOutcome",
"text": {
"status": "generated",
"div": "Invalid request"
},
"issue": [
{
"severity": "fatal",
"code": "invalid",
"expression": [
""
],
"diagnostics": "'resource' is a required property"
}
]
}
@pavlushkin you're sure that that's not your App response? The object sent from Aidbox will have body in the "body" instead of "resource" attr
@KGOH we cannot change the header to plain/text
since it is a big change in exposed API.
We are ok with 422 response from Aidbox.
@pavlushkin got you. We can do this this week. Is that ok?
@KGOH yes, that would be great. Thank you!
Hi @pavlushkin!
Aidbox is now able to handle invalid JSON (and other formats) errors on edge
version, starting from v:2302.42ecede6
. It wraps them in OperationOutcome
with status 400. (Not 422 because 422 corresponds to business-level errors, see FHIR Http spec.)
Hi @pavlushkin! Aidbox is now able to handle invalid JSON (and other formats) on
edge
version, starting fromv:2302.42ecede6
. It wraps them inOperationOutcome
with status 400. (Not 422 because 422 corresponds to business-level errors, see FHIR Http spec.)
Thanks, that works well!