Skip to content

Enhancement/Bug Respect Accept header in error reporting  #9

@ahenket

Description

@ahenket

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>
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions