Conversation
|
|
|
Reviewed PR #3725. Found a redundant/dead code path in the error-handling logic at Task list (6/6 completed)
|
|
@atomicpages is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
|
|
TL;DR — Upgrades the Key changes
Summary | 35 files | 2 commits | base: Ky 2 error handling with
|
| import type { HTTPError, Options as KyOptions } from 'ky'; | ||
| import ky from 'ky'; | ||
| import type { Options as KyOptions } from 'ky'; | ||
| import ky, { isHTTPError } from 'ky'; |
There was a problem hiding this comment.
this was available in later version of ky v1, not required to use, but helps with tsc
There was a problem hiding this comment.
Important
Two issues to address: a dead/redundant code path in the error-handling logic, and a personal editor setting that leaked into the diff.
| jsonError = JSON.parse(textError); | ||
| } catch { | ||
| jsonError = undefined; | ||
| if (kyHttpError) { |
There was a problem hiding this comment.
This is due to:
- Make .json() throw on empty bodies and 204 responses instead of returning an empty string (Make
json()throw on empty responses sindresorhus/ky#854) sindresorhus/ky@1b8e1ff - Make beforeError hook receive all errors, not just HTTPError (Make
beforeErrorhook receive all errors sindresorhus/ky#829) sindresorhus/ky@101c74b
| if (error && typeof error === 'object' && 'response' in error) { | ||
| const httpError = error as HTTPError; | ||
| response = httpError.response; | ||
| if (isHTTPError(error)) { |
There was a problem hiding this comment.
This should be safe to use: https://github.com/sindresorhus/ky/blob/7d23d68e2614777f240896060f31d77f74f1a0d2/source/utils/type-guards.ts#L8
| export const client = createClient( | ||
| createConfig<ClientOptions2>({ baseUrl: 'https://petstore3.swagger.io/api/v3' }), | ||
| ); | ||
| export const client = createClient(createConfig<ClientOptions2>({ baseUrl: '/api/v3' })); |
|
Acknowledged the author's correction on the truthiness thread — Task list (2/3 completed) |
|
Fixed the bug in the final error branch of Task list (4/4 completed)
|


Config/kyOptionstypes: omitprefixinstead of removedprefixUrl.HTTPErrorwithisHTTPError, useerror.datawhen Ky has consumed the body, and fall back toresponse.text()when the body is still readable (e.g. tests).dataand a failingresponse.text().openapi-ts-testssnapshots for@hey-api/client-ky; bumpkyto 2.x in the Ky example and test package; regenerate example client output.docs/openapi-ts/clients/ky.mdfor Ky 2,prefixUrl→prefix, andkyOptionsexample.Note: the tests I delegated to cursor. I'm happy to either revert and/or amend any changes. LMK