Skip to content

Create nice error writers #654

Closed

Description

@RubenVerborgh

We should have content-negotiable error writers, (partially) reusing the infrastructure we currently have for content-negotiated responses.

This will enable nicer error messages.

A particular case is just serving Databrowser in case of 403.

Activity

  1. jvherweg commented on Mar 5, 2021

    @jvherweg
    Member

    Having an error writer that returns an html page instead of what we do know is easy, would just require the html and css in which we then inject the error message/status code.

    To make it dynamic based on the accept header we could link multiple error writers in a waterfall handler and have them check the preferences value in the canHandle function. This would require a change in the ResponseWriter interface since that doesn't accept RepresentationPreferences as input currently. Perhaps we could just add the entire Operation object as input in case they need to know something else.

  2. RubenVerborgh commented on Mar 6, 2021

    @RubenVerborgh
    MemberAuthor

    would require a change in the ResponseWriter interface

    Can't we just entirely reuse the RepresentationConvertor mechanism? Such that future benefits like #484 can also be reused?

  3. jvherweg commented on Mar 8, 2021

    @jvherweg
    Member

    To re-use that we would need more layers though.

    RepresentationConverter takes as input a Representation and RepresentationPreferences (and an identifier), and outputs a new Representation based on the values found in both the metadata and the preferences.

    ResponseWriter takes (for error response writers at least) an Error and an HttpResponse, and writes a representation of that error (currently just the stack trace) to the response. So to re-use the converters, we would first have to convert the error to a Representation, feed it into the converter mechanism and then pipe that to the response writer (this layer we already have). The only case where the middle converters would be useful is if a media type is requested for which we do not have an error->type converter. E.g., we have an ErrorToTurtle class but JSON-LD is requested. It's more overhead, but we could re-use the BasicResponseWriter also for errors then.

    Is it really important to support error types in multiple media types though? I would think this is something where mostly the status code is important (and html in case something visual is needed), so having an html writer and the one we have now would be enough.

    (At this point I'm even thinking, can't we just fully work API-based and let something else handle the html ;) )

  4. RubenVerborgh commented on Mar 10, 2021

    @RubenVerborgh
    MemberAuthor

    we would first have to convert the error to a Representation

    Why don't we turn the Error into a representation indeed? Let's say, a new internal type for errors?

    The only case where the middle converters would be useful is if a media type is requested for which we do not have an error->type converter. E.g., we have an ErrorToTurtle class but JSON-LD is requested.

    Exactly. All we need is ErrorToRdf, the rest we reuse.

    Is it really important to support error types in multiple media types though?

    Definitely already HTML and machine-readable, so yes.

    can't we just fully work API-based and let something else handle the html

    Good point, but resources (like images and video) can also be accessed directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions