-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve 204 support #24
Conversation
src/client.ts
Outdated
|
||
if (bodyParseResult.error === 'EMPTY_RESPONSE') { | ||
if (params.isEmptyResponseExpected) { | ||
return response as unknown as Promise<ResponseBody> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejsevcik @szymonchudy How would FE prefer to be communicated about special cases? Currently it would just return entire Response object in case something isn't considered a direct error, but is an unusual situation (e. g. non-JSON or expected as possible empty content came back). Is that good enough? We can return an Either with a defined set of possible result codes instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the isEmptyResponseExpected
is true, then this is not really an error case from the point of the caller. I would expect that it would return successful promise resolution with undefined/void value.
The code could check the response status, and if it is 204, then the parsing should be skipped IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the isEmptyResponseExpected is true, then this is not really an error case from the point of the caller. I would expect that it would return successful promise resolution with undefined/void value.
Fair point. We can use a more bespoke structure then Either then, with three possible fields: Left (error), Middle (non-error deviation from main path) Right (expected main path response). If Right is set, we proceed with the main path, if left is set, we handle an error, if Middle is set, we check the code returned and handle it in a custom way.
The code could check the response status, and if it is 204, then the parsing should be skipped IMO.
Aren't we already doing that in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kibertoad maybe I'm looking at a wrong line, but I think we're not checking the status before parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejsevcik check the tryToResolveJsonBody
itself
@CarlosGamero We probably should have the check in the consistent place for both GET and non-GET scenarios, I think currently I did it explicitly for non-GET and implicitly (within tryToResolveJsonBody
) for GET.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kibertoad I will change it to use the same approach on both places 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already changed
Changes
ToDo:
Checklist
major
,minor
,patch
orskip-release