Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Improved Exception Handling #170

Closed
dehall opened this issue Mar 22, 2024 · 0 comments
Closed

Request: Improved Exception Handling #170

dehall opened this issue Mar 22, 2024 · 0 comments

Comments

@dehall
Copy link
Contributor

dehall commented Mar 22, 2024

There are a few ways the Validation Service can throw, and digging into the root cause of the problem is challenging:

  • The full stack trace is not reported in the log
  • Errors are not caught, which results in a blank response and nothing in the log. Not catching Error is usually best practice, but the core validator can throw Error in situations I think should be Exceptions, for example a profile URL that doesn't resolve. See sample request that throws an Error at the bottom of this message.
  • The exception message is returned in the response body as just a string

I would propose the following, which I'm happy to implement but wanted a sanity check before submitting an unsolicited PR:

  1. Log the full stack trace of the exception caught in this block instead of just the localized message
    try {
    call.respond(HttpStatusCode.OK, validationController.validateRequest(request))
    } catch (e: Exception) {
    logger.error(e.localizedMessage)
    call.respond(HttpStatusCode.InternalServerError, e.localizedMessage)
  2. Change the catch to Throwable so that it will catch Error as well (then maybe re-throw Errors after responding?)
  3. Wrap the exception in a ValidationResponse with level FATAL, that way the response structure is the same regardless of success or error. The HTTP status code would still indicate server error, bad request, or ok as appropriate.

Sample request that throws Error internally and results in a blank response body:

{
    "cliContext": {
        "sv": "4.0.1",
        "profiles": ["http:https://hl7.org/fhir/us/core/StructureDefinition/us-core-doesntexist"]
    },
    "filesToValidate": [
        {
            "fileName": "manually_entered_file.json",
            "fileContent": "{\"resourceType\":\"Patient\"}",
            "fileType": null
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants