Repository navigation
Treat HTTP 520 to 524 from the Admin API as gateway errors - #9042
isaacroldan wants to merge 2 commits into
Conversation
alexanderMontague
left a comment
There was a problem hiding this comment.
Approving. Both consumers of isGatewayErrorStatus are accounted for and the change makes sense in each:
isExpectedApiError— rawClientErrors with 520–524 stop being reported as unexpected. This only matters on thehandleErrors: falsepath (theme reads); the default path already wraps 5xx into anAbortErrorinerrorHandler, so no inconsistency is introduced.device-authorization.ts— now also retries 520–524 and throwsAbortErrorinstead ofBugErroron an unparseable body. The POST to/oauth/device_authorizationjust mints a new device code, so retrying is safe.
Two non-blocking points:
Question: why stop at 524? Cloudflare also returns 525/526 (origin TLS failures) and 530. Those are also HTML edge pages that would still be reported as unexpected. Excluding them from retry makes sense (they're not transient), but if the goal is "don't blame the CLI for edge errors", you may want them in isExpectedApiError too. Fine to leave as-is if you'd rather keep one list.
Nit: the themes/api.test.ts test mocks adminRequestDoc to reject, so "when the edge answers HTTP 520" isn't really what's exercised — it proves requestThemeAdminDoc rethrows the ClientError unchanged and then re-asserts the unit test. Still a reasonable thing to lock down, but the name overstates it.
Generated with Pi. Vetted by Me.
Theme Admin API reads use handleErrors: false, so a raw ClientError reaches shouldReportErrorAsUnexpected. When the Cloudflare edge answers 520 to 524 with an HTML error page, isExpectedApiError did not match it and the CLI reported an infrastructure failure as an unexpected error. Add 520 to 524 to the gateway statuses in status-checks.ts. 500 stays out, because it can be a real server bug. The device authorization flow uses the same helper, so it now also retries these statuses. Co-authored-by: isaac.roldan <isaac.roldan@shopify.com>
4763b40 to
bccd823
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/private/node/api/status-checks.d.ts@@ -2,6 +2,6 @@
* Checks whether an HTTP status indicates a gateway-level failure.
*
* @param status - The HTTP status to check.
- * @returns Whether the status is 502, 503, or 504.
+ * @returns Whether the status is 502, 503, 504, or a Cloudflare edge error from 520 to 524.
*/
export declare function isGatewayErrorStatus(status: number | undefined): boolean;
\ No newline at end of file
|
WHY are these changes introduced?
Theme Admin API reads use
handleErrors: false. So a rawClientErrorfromgraphql-requestreachesshouldReportErrorAsUnexpected. When the Cloudflare edge in front of the API answers HTTP 520 to 524, the body is an HTML error page ("Something went wrong"), not JSON.isExpectedApiErroraccepts only 401, 429, 502, 503 and 504. So the CLI reports this infrastructure failure as an unexpected error, as if it were a CLI bug.WHAT is this pull request doing?
GATEWAY_ERROR_STATUSESinpackages/cli-kit/src/private/node/api/status-checks.ts. HTTP 500 stays out, because it can come from a real server bug.isExpectedApiErrornow treats a rawClientErrorwith these statuses as an expected gateway error.AbortError, the same as 502, 503 and 504.error/index.test.ts(520 to 524 are expected, 500 is still unexpected) andthemes/api.test.ts(fetchThemesthat gets a 520 HTML response throws an error that is not reported as unexpected).How to manually test your changes?
pnpm install.packages/cli-kit/check-gateway.ts:pnpm tsx check-gateway.tsinpackages/cli-kit.500 true,502 false,520 false,524 false. Onmain, 520 and 524 printtrue.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add