-
-
Notifications
You must be signed in to change notification settings - Fork 442
Changes type of retry.methods option to HttpMethod #789
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
base: main
Are you sure you want to change the base?
Conversation
source/types/common.ts
Outdated
| | LiteralType | ||
| | (BaseType & {_?: never}); | ||
|
|
||
| export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete'; |
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.
Had to move this to common so that there is not a circular dependency between retry.ts and options.ts
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.
Circular dependencies are fine in ESM.
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.
Right, I think this is just a tick from some past projects :) I'll move the HttpMethod back to options.ts
source/types/common.ts
Outdated
| | LiteralType | ||
| | (BaseType & {_?: never}); | ||
|
|
||
| export type RequestHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' ; |
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.
For some reason, in constants.ts there is an exported constant containing methods without 'options' and 'trace'
// source/core/constants.ts
...
export const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'] as const;I guess we want to keep split the methods that the user does proactively (rather than the browser doing automatically) and all available methods.
The default retryMethods however contain also options and trace as a default:
// source/utils/normalize.ts
const retryMethods: Array<HttpMethod> = ['get', 'put', 'head', 'delete', 'options', 'trace'];|
I appreciate you working to prevent the uppercase method mistake. However, hardcoding Instead, we should use the methods?: Array<LiteralUnion<HttpMethod, string>>;This provides autocomplete for common methods while still accepting any string, maintaining both type safety and extensibility. |
37ea1ac to
8340cd7
Compare
Ok, that makes sense.. In that case, would it make sense to you if I lowercased the passed methods in |
0ffc5c2 to
87c9848
Compare
source/core/Ky.ts
Outdated
|
|
||
| // Check if method is retriable for non-forced retries | ||
| if (!this.#options.retry.methods.includes(this.request.method.toLowerCase())) { | ||
| if (!this.#options.retry.methods.includes((this.request.method.toLowerCase()))) { |
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.
Was this change meant to be included?
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, sorry, was removing a typecast and my IDE left the braces
I learned the hard way that the methods need to be lowercase (and kept wondering why the requests are not retried). This change should prevent that mistake