-
Notifications
You must be signed in to change notification settings - Fork 272
Conversation
codecov is stuck in processing, hopefully will post eventually |
@@ -75,14 +75,15 @@ class SupersetClient { | |||
); | |||
} | |||
|
|||
get({ host, url, endpoint, mode, credentials, headers, body, timeout, signal }) { | |||
get({ body, credentials, headers, host, endpoint, mode, parseMethod, signal, timeout, url }) { |
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.
It starts to get long, do you want to separate into one param per line?
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.
Oh just notice post
is already doing that, then maybe good to spread this one out too.
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.
it's all based on prettier config, it auto wraps if it's over the 100 char limit (which post
is but get
is not). we could decrease the char limit if you feel strongly about it tho.
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.
nope. this is pretty minor. I'll leave it to you.
}; | ||
|
||
export default function parseResponse(apiPromise, parseMethod = 'json') { | ||
const responseParser = PARSERS[parseMethod] || PARSERS.json; |
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.
Can developer pass parseMethod
as a custom function in addition to string of predefined parser name?
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.
I thought about that but am not sure a free-form parser makes sense. There are only a few available on the Response object, of which we are exposing text
and json
.
It doesn't seem worthwhile to copy / mirror the full response API to me (would begin questioning the need for this lib). One option could be to allow null
or 'none'
as a parseMethod
to enable returning the response unmodified and un-read. Beyond that, any custom parsing I think should come from a chained .then(({ json }) => myCustomParser(json))
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.
sgtm
// HTTP 404 or 500 are not rejected, ok is just set to false | ||
if (!response.ok) { | ||
return Promise.reject({ | ||
error: response.error || (json && json.error) || text || 'An error occurred', |
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.
Perhaps should separate error handling for apiResponse
, json
parsing and text
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.
return apiPromise
.then((response) => {
if (!response.ok) {
return Promise.reject({
error: response.error,
status: response.status,
statusText: response.statusText,
});
}
return response;
})
.then(responseParser)
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.
I dig the latter^
}); | ||
} | ||
.then(json => ({ json, response })) | ||
.catch(() => /* jsonParseError */ response.text().then(text => ({ response, text }))), |
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.
Does this mean the developer always have to check if output.json
exists or not? If output.json
does not exist, they should use to output.text
instead. If they forget to check. This can cause bugs. I wonder if there is a way to make it more explicit.
Also, generally, does one expect this Promise to reject when fail to parse or resolve text of the supposed-to-be json? IMO, I would expect it to fail and give me the text in the error message for debugging.
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.
Yeah now that we expose the parse method and are explicit about text
/json
we should probably not clone and fallback to text
gracefully, and instead it should probably throw.
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.
this broke a lot of tests, which were falling back to .text()
unknowingly because of my mock text response 😜
…son, allow for null responseParser
just noting that
|
I will also fix the |
* chore: enable live TS in Storybook * chore: 🤖 manually add tsconfig for storybook * chore: 🤖 enable typescript for preset-chart-xy
🏆 Enhancements
parseMethod
argument toparseResponse
in order to support bothjson
(default) andtext
responses. This is needed to enable custom response parsing in some cases, for exampleBigInt
s which was added to Sqllab recently.parseMethod
as an optional argument toSupersetClient.get()
and.post()
calls.🏠 Internal
@data-ui/build-config
to0.0.14
which has a stricterno-unused-args
eslint rule.npmrc
to.gitignore
for local publishing credentials@kristw @conglei @mistercrunch