Repository navigation
Convert errors to Representations - #760
Conversation
RubenVerborgh
left a comment
There was a problem hiding this comment.
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" } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
BaseHttpServerFactoryalso 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.
83442a9 to
e755f55
Compare
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
WwwAuthMetadataWriterthat 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:
TextErrorHandlerinstead of aErrorToTextconverter was because I wanted a solution that had the least chances of erroring as a backup in case something went wrong in theConvertingErrorHandler.AuthenticatedLdpHandlerunit tests since it was clear they were written when I had less of an idea on how to use jest.