Skip to content

Convert errors to Representations - #760

Merged
jvherweg merged 3 commits into
mainfrom
feat/error-writer
Jun 7, 2021
Merged

jvherweg merged 3 commits into
mainfrom
feat/error-writer

Conversation

@jvherweg

@jvherweg jvherweg commented Jun 3, 2021

Copy link
Copy Markdown
Member

Based on the discussion in #654 .

This doesn't solve that issue since I still need to add an ErrorToHtml converter, but that should be easy after these changes. Same for the WwwAuthMetadataWriter that would be needed for #655, which can use the status code that is now added to the metadata.

Adding those 2 things is the next thing I'll do, but this part could already be pushed since it stands on its own.

Some comments:

  • The IDP handler currently fixes the media type of the error response to text/plain since it doesn't have access to the preferences. Similarly, the LDP handler will do the same if there is an error in the RequestParser since it doesn't have the preferences yet at that point. This makes me wonder if perhaps we want to extract the preferences at an earlier point? We could also use our current preference parser in the IDP part, and perhaps even create a helper class/function to do preference extraction + error -> response + write response.
  • The reason for having a TextErrorHandler instead of a ErrorToText converter was because I wanted a solution that had the least chances of erroring as a backup in case something went wrong in the ConvertingErrorHandler.
  • I used this opportunity to rewrite the AuthenticatedLdpHandler unit tests since it was clear they were written when I had less of an idea on how to use jest.

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, super excited to have this!

"interactionHttpHandler": { "@id": "urn:solid-server:auth:password:InteractionHttpHandler" },
"errorResponseWriter": { "@type": "ErrorResponseWriter" }
"errorHandler": { "@id": "urn:solid-server:default:ErrorHandler" },
"responseWriter": { "@id": "urn:solid-server:default:ResponseWriter" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't expected this to be at the level of identity, but rather at the level of the server, or some other top handler. So that any error thrown are all handled the same way.

Although I see it's only IDP, so looks like every subsystem (LDP, IDP) just has it own.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree actually, that's what I meant with "extract the preferences at an earlier point" above. It might make sense to extract the preferences in the BaseHttpServerFactory and catch all errors there, instead of doing it in the HttpHandlers. This way we have a single place where error responses are handled. The only reason this was also added now to the IDP is because I previously changed it to use an error responsewriter instead of just returning the error. The StaticAssetHandler doesn't have this yet for example so just throws errors to the server factory.

The one disadvantage would be that then there would be no way for different HttpHandler to have different metadata writers for errors that are thrown. Currently this is not needed yet though.

We could also keep the current solution but then we probably want to, at least for the IDP, find a way to extract preferences there so you don't get a text error while going through the html UI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additonal confusion: the current BaseHttpServerFactory also has a try/catch for errors which writes out the error stack (which is how the StaticAssetHandler errors get returned). So there is some duplication where errors are handled.

@RubenVerborgh RubenVerborgh Jun 4, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it as-is. It keeps the different subsystems independent.

However, let's move (in another PR, or this one)

      const preferences: RepresentationPreferences = { type: { 'text/plain': 1 }};
      const result = await this.errorHandler.handleSafe({ error, preferences });
      await this.responseWriter.handleSafe({ response: input.response, result });

to a single class, which is then the errorWriter that we pass (instead of errorHandler and responseWriter).
That errorWriter can then also have a preferences extractor.


the current BaseHttpServerFactory also has a try/catch for errors which writes out the error stack

That's the (server-specific) emergency solution for when even error handling fails; let's keep that in place.


Just a small note for future reference:

It might make sense to extract the preferences in the BaseHttpServerFactory

This factory should really only make the main server.
Extracting preferences can be done as just an HTTP handler that is reusable with any server.

Comment thread src/ldp/http/ConvertingErrorHandler.ts Resolved
Comment thread src/ldp/http/ResponseWriter.ts Resolved
Comment thread src/ldp/http/TextErrorHandler.ts Resolved
Comment thread src/util/Vocabularies.ts Resolved
@jvherweg
jvherweg force-pushed the feat/error-writer branch from 83442a9 to e755f55 Compare June 7, 2021 11:46
@jvherweg
jvherweg merged commit b604dd8 into main Jun 7, 2021
@jvherweg
jvherweg deleted the feat/error-writer branch June 7, 2021 11:54
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

Successfully merging this pull request may close these issues.

3 participants