refactor: typed HTTPError and response-shape detection in apiPull#50
Merged
Merged
Conversation
- Add `HTTPError` class with `status` / `statusText` fields. `fetchApi` throws it on non-2xx responses; `handleAsyncErrors` matches the 401 hint by `error instanceof HTTPError && error.status === 401` instead of regex-matching the message string (which broke when Loco varied the wording between `Unauthorized` and `Authorization Required`). - `apiPull` decides whether to wrap the `/export/all.json` payload based on the response itself (top-level keys all match known locale codes ⇒ already locale-keyed) instead of inferring purely from the separate `/locales` count. Same number of API calls, more robust against locale-list races and future Loco shape changes. - Tests assert `instanceof HTTPError` + `.status` instead of message substring match.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HTTPErrorclass with typedstatus/statusTextfields.fetchApithrows it on non-2xx responses;handleAsyncErrorsnow matches the 401 access-key hint byerror instanceof HTTPError && error.status === 401instead of regex-matching the message string (which broke when Loco varied the wording betweenUnauthorizedandAuthorization Required).apiPulldecides whether to wrap the/export/all.jsonpayload based on the response itself — if every top-level key matches a known locale code, it's already locale-keyed and we leave it alone. Single-locale flat responses still get wrapped under the project's locale code. Same number of API calls (still 2 in parallel), more robust against locale-list races and future Loco shape changes.instanceof HTTPError+.statusinstead of message-substring matches.Smoke-tested end-to-end against a live multi-locale Loco project: pull, status (clean + dirty), push, and 401-with-invalid-key — all behave as expected.
Test plan
pnpm build && pnpm test && pnpm lint && pnpm format:checkall passloco-cli pullagainst a multi-locale project still returns the locale-keyed shapeloco-cli pullagainst a single-locale project still wraps the flat response under the locale codeloco-cli pullwith an invalid access key prints the friendly hint and exits 1loco-cli pushstill uploads per-locale and surfaces Loco's response message