-
Notifications
You must be signed in to change notification settings - Fork 105
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
refactor - Faucet: clean up faucet API & pow utils #627
Conversation
e832a7b
to
83a537a
Compare
83a537a
to
c3c6943
Compare
c3c6943
to
d007863
Compare
5a4a44e
to
fb2df8c
Compare
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.
LGTM!
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.
Looks good to me and the code looks much cleaner! I just left a couple of minor comments.
} | ||
const reader = response?.body?.getReader(); | ||
return reader | ||
?.read() |
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.
Not sure if it matters, but I think this can still return a resolved Promise<undefined>
even though the methods that use this return Promise<ChallengeResponse>
etc.
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.
Actually, I was trying to figure out why TypeScript doesn't catch that. I'm not 100% sure, but if you add a return type to the then
callback, it will catch it:
return (await fetch(new URL(`${this.url}${endpoint}`), {
...options,
})
.then((response): Promise<T> => {
TS2322: Type 'Promise<T> | undefined' is not assignable to type 'Promise<T>'.
Type 'undefined' is not assignable to type 'Promise<T>'.
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.
Thanks! I'll take a look. I think in the case it can return undefined
, we should throw an exception so it can be caught in the app. I wanted to remove any case of undefined
as it's very tedious
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 added a type for that error response, with { message, code }
, so a correctly parsed error should always be this type, and in the case of undefined
(if it can't get the reader and parse the error response) it will instead throw an error
fb2df8c
to
c7cb7c3
Compare
c7cb7c3
to
9b81184
Compare
This PR is to clean up the utils & return types used in Faucet app. We can add any other improvements here as well.