Skip to content

Fix error presentation issues by passing the Request object - #1314

Merged
jvherweg merged 2 commits into
versions/5.0.0from
fix/request-error-preferences
Jun 1, 2022
Merged

jvherweg merged 2 commits into
versions/5.0.0from
fix/request-error-preferences

Conversation

@jvherweg

Copy link
Copy Markdown
Member

Alternative solution 1 for #1309

This introduces the suggested change of having the ErrorHandler take the request object as input instead of the preferences.

This is definitely the least invasive of the changes. It does potentially parse the Accept headers up to 3 times. We could cache in theory but I don't think it's really necessary for such a cheap operation.

The main issues are that it feels a bit strange that we pass the raw request object after we have already created a parsed Operation object, and that the ConvertingErrorHandler is responsible for both parsing accept headers and calling the converter with the error object.

@jvherweg
jvherweg requested a review from RubenVerborgh May 13, 2022 14:08

@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.

I like this.

Comment thread RELEASE_NOTES.md Resolved
private readonly showStackTrace: boolean;

public constructor(converter: RepresentationConverter, showStackTrace = false) {
public constructor(converter: RepresentationConverter, preferenceParser: PreferenceParser, showStackTrace = false) {

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 wonder if we want a full BasicRequestParser for forward compatibility (and we cache).

}

const result = await this.errorHandler.handleSafe({ error, preferences: { type: { 'text/plain': 1 }}});
const result = await this.errorHandler.handleSafe({ error, request: guardStream(ctx.req) });

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.

The extra guardStream surprises me here; do we lose any properties of the request?

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.

Our interfaces require guarded streams everywhere. At this point the incoming request has not yet been guarded at some point since it was fully handled by the OIDC library.

Guarding a stream only adds some extra listeners so nothing is lost. In practice it doesn't do anything here since if there was data it has already been read out by the OIDC library. This is just to conform to our typing requirements.

Comment thread src/server/ParsingHttpHandler.ts Resolved
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.

2 participants