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

Enhancement/Bug Respect Accept header in error reporting #9

Open
ahenket opened this issue Jan 9, 2021 · 0 comments
Open

Enhancement/Bug Respect Accept header in error reporting #9

ahenket opened this issue Jan 9, 2021 · 0 comments

Comments

@ahenket
Copy link
Contributor

ahenket commented Jan 9, 2021

In roaster 1.0.0 when an error gets triggered, this is always json and in rare cases xml regardless of the Accept header in the client request. This is due to two things:

  • The code usually works with map objects and conversion to xml is not defined from there
  • The code just implements json in various places e.g. in router:default-error-handler

For this reason we set up our own x-error-handler, which does a second thing: when the error is a client error, we don't return module|line|column because the client would not be interested in that part. For server errors we obviously have something going on we actually need to look at on the server and thus we include those.

We explicitly call roaster:response with head(roaster:accepted-content-types()) to have the biggest chance for the right response type. Note that roaster:get-content-type-for-code() would have been better, but that function is still in the router module.

let $responsecode   := errors:get-status-code-from-error($errmap?code)
return
    roaster:response($responsecode, head(roaster:accepted-content-types()), 
        <error>
            <code>{$errmap?code}</code>
            <description>{$errmap?description}</description>
        {
            if ($responsecode lt 500) then () else (
                <module>{$errmap?module}</module>,
                <line>{$errmap?line}</line>,
                <column>{$errmap?column}</column>
            )
        }
        </error>
    )
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

1 participant