Repository navigation
Conversation
There was a problem hiding this comment.
It does not sit well with me. It feels like something is off.
What feels uneasy is this:
export interface RequestParserInput {
request: HttpRequest;
preferences: RepresentationPreferences;
}So we have a parser that accepts a partially parsed request.
Meaning there is another parser somewhere.
I can't think of a proper name for this new RequestParser object, and I take that as a sign that there is no clear boundary of what it does and doesn't.
I think the actual problem is that some output producers need these preferences.
So in that sense, how about we instead pass request to errorHandler? After all, an error is handled in response to a request, so it's not weird for an error handler to know about the request that caused the error. Then we preference parse that request and we're done? (The only downside seems to be possible double preference parsing; caching can fix that.)
|
|
||
| // Also change the error message in the stack trace | ||
| if (error.stack) { | ||
| error.stack = [ `${error.name}: ${error.message}`, ...error.stack.split('\n').slice(1) ].join('\n'); |
There was a problem hiding this comment.
Why not just error.stack.replace(/.*/, `${error.name}: ${error.message}`)?
There was a problem hiding this comment.
Because my regex-fu is simply not strong enough.
I get the issue. Passing the request object to the error handler could work, the issue there is that I don't like that the request object is still being used after we made the Operation object. Yes the error is handled in response to a request, but literally everything the server does is in response to a request. The ErrorHandler's core goal is converting an Error to a ResponseDescription. I'll explain the solution I had first, might be relevant, but I reverted it because it felt more invasive than it needed to be and perhaps made the Originally I completely removed the |
|
Just my two cents: I've looked at all options (out of curiosity) and my preference would be alternative 2, where you are moving all the parsing to the ParsingHttpHandler. It feels to me like that has the best separation of concerns. You are also not passing around On the original suggestion: I can follow the original concern mentioned by @RubenVerborgh here about the On the first alternative: personally not a fan of passing the |
Not entirely sure about that, though. I dislike that callers have to prepare the preferences; they should not know about these things.
Agreed.
Does it make sense to replicate the same in alternative 1? In any case, I feel that 1 is the way to go. My 2 cents. |
I sort of get that, although I think it should be more the responsibility of the class throwing the error in the first place to provide relevant information about which part of the request was causing the issue. The same argument could also be used to say that we should pass the entire internal state that we have to the error handler so it can provide even more debugging information in case of error.
It's not really relevant in alternative 1 since there the
This is a comment from the review on alternative 1 but wanted to place it here to have the discussion in 1 place and I think it's relevant to the total picture. It's important to remember that the main goal of this PR is to make sure we also have content negotiation on errors that get thrown before the request could be (fully) parsed. So if we use the The above makes me wonder if we should perhaps have a
I'm OK with going for that one since it does fix the issue with not that drastic of a requirement change tbh. But I do find the discussion interesting 😄 |
|
Done in #1314 |
📁 Related issues
#1148 (comment)
✍️ Description
Fixes several issues I still had with how we showed errors to the users. There were still several cases where the user would get a text representation of the error, even if they requested HTML or something else. This PR fixes all of those cases (I think).
The
PreferenceParserhas been extracted from theBasicRequestParserand moved to theParsingHttpHandler. This way we can parse the preferences before any error gets thrown by, for example, an invalid N3 Patch body that gets parsed.The
IdentityProviderFactorynow also takes aPreferenceParseras input so it can correctly create a representation for OIDC errors. The extra error metadata that gets added now only gets added if theshowStackTraceparameter has been set to true to make sure we don't leak too much information. Although that is not (yet) super relevant due to #1182 .This does overload the
IdentityProviderFactoryclass a bit, we could always split it up in the future but I think it's fine since it hides all the configuration for theoidc-providerlibrary.