Harden API response error handling and fix Windows build compatibility#22
Open
KAvinash47 wants to merge 8 commits into
Open
Harden API response error handling and fix Windows build compatibility#22KAvinash47 wants to merge 8 commits into
KAvinash47 wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens the frontend API client by converting non-2xx HTTP responses into structured ApiErrors and adds a TypeScript test suite to validate error handling paths. It also updates build.py to improve Windows compatibility and includes diagnostic metadata artifacts.
Changes:
- Refactors
request<T>()to throw on!response.okand addsparseErrorResponse()/ status-based suggestions. - Adds a focused TS test suite for success + multiple error scenarios.
- Adjusts
build.pysubprocess execution details for Windows and commits diagnostic metadata JSONs.
Reviewed changes
Copilot reviewed 10 out of 14 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/services/api.ts | Throws structured ApiError on non-2xx responses; adds error parsing + status suggestions. |
| frontend/src/services/api.test.ts | Adds unit tests covering success and several error paths via mocked fetch. |
| build.py | Updates Windows-related subprocess/env handling and encryptly CWD/stdin behavior. |
| diagnostic/build-d8f1123e.json | Adds diagnostic metadata for a successful frontend build (includes local paths/password). |
| diagnostic/build-ad075519.json | Adds diagnostic metadata for a successful frontend build (includes local paths/password). |
| diagnostic/build-a80b1dc0.json | Adds diagnostic metadata for an encryptly preflight failure. |
| diagnostic/build-6e6ebe98.json | Adds diagnostic metadata for a successful frontend build (includes local paths/password). |
| diagnostic/build-647a124c.json | Adds diagnostic metadata for an encryptly preflight timeout. |
| diagnostic/build-3d7f3362.json | Adds diagnostic metadata for an encryptly preflight timeout. |
| diagnostic/build-33992f18.json | Adds diagnostic metadata for a successful frontend build (includes local paths/password). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+263
to
+266
| const isApiError = (err: any): err is ApiError => | ||
| err && typeof err === 'object' && 'code' in err && 'message' in err; | ||
|
|
||
| const apiError = isApiError(lastError) ? lastError : normalizeError(lastError); |
Comment on lines
+353
to
+364
| const json = await response.json(); | ||
| if (json && typeof json === 'object') { | ||
| const payload = json.error && typeof json.error === 'object' ? json.error : json; | ||
| message = payload.message || payload.error || message; | ||
| if (payload.details && typeof payload.details === 'object') { | ||
| details = payload.details; | ||
| } else { | ||
| const { message: _, error: __, details: ___, requestId: rId, path: p, ...rest } = payload; | ||
| if (Object.keys(rest).length > 0) { | ||
| details = rest; | ||
| } | ||
| } |
Comment on lines
+17
to
+27
| # Reconfigure stdout/stderr to UTF-8 on Windows to avoid UnicodeEncodeError on emojis | ||
| if sys.stdout.encoding.lower() != 'utf-8': | ||
| try: | ||
| sys.stdout.reconfigure(encoding='utf-8') | ||
| except Exception: | ||
| pass | ||
| if sys.stderr.encoding.lower() != 'utf-8': | ||
| try: | ||
| sys.stderr.reconfigure(encoding='utf-8') | ||
| except Exception: | ||
| pass |
Comment on lines
428
to
439
| def clean_module(module: Module, verbose: bool = False) -> bool: | ||
| print(f" {color('▸', Colors.YELLOW)} Cleaning {module.name}...") | ||
| try: | ||
| subprocess.run( | ||
| module.clean_cmd, | ||
| cwd=str(module.dir), | ||
| capture_output=not verbose, | ||
| text=True, | ||
| timeout=60, | ||
| env=os.environ.copy(), | ||
| shell=(platform.system().lower() == "windows"), | ||
| ) |
Comment on lines
+9
to
+10
| "password": "6f3678ce8859438eab1e", | ||
| "decrypt_command": "encryptly unpack diagnostic\\build-6e6ebe98.logd <outdir> --password 6f3678ce8859438eab1e", |
| "name": "frontend", | ||
| "status": "PASS", | ||
| "elapsed_seconds": 4.44, | ||
| "artifact": "C:\\Users\\AVINASH KUMAR\\TentOfTrials\\frontend\\dist", |
Comment on lines
+9
to
+10
| "password": "69535d5ce1f02a62d10b", | ||
| "decrypt_command": "encryptly unpack diagnostic\\build-ad075519.logd <outdir> --password 69535d5ce1f02a62d10b", |
| "name": "frontend", | ||
| "status": "PASS", | ||
| "elapsed_seconds": 4.352, | ||
| "artifact": "C:\\Users\\AVINASH KUMAR\\TentOfTrials\\frontend\\dist", |
Comment on lines
+9
to
+10
| "password": "a16b0d1864a85ff03c58", | ||
| "decrypt_command": "encryptly unpack diagnostic\\build-33992f18.logd <outdir> --password a16b0d1864a85ff03c58", |
| "name": "frontend", | ||
| "status": "PASS", | ||
| "elapsed_seconds": 4.445, | ||
| "artifact": "C:\\Users\\AVINASH KUMAR\\TentOfTrials\\frontend\\dist", |
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
This PR resolves the $40 TypeScript API Response Error Handling bounty and fixes Windows build compatibility.
Changes
1. Hardened TypeScript API Response Error Handling
request<T>()infrontend/src/services/api.tsto reject and throw immediately on non-2xx HTTP responses instead of returning them as successful responses.parseErrorResponse()helper:ApiError.message,details,requestId, andpath.message.normalizeError()helper (retaining status codes and details) but still run through theerrorInterceptorschain (such as 401 token refresh attempts and 429 rate limit warnings) before rejection.429maps to "Too many requests. Please wait a moment before trying again.").frontend/src/services/api.test.tsvalidating all 6 paths (Success, 401 JSON, 429 Rate Limit, 500 Text, Timeout, Network Error).2. Windows Build Compatibility Fixes
HOMEandUSERPROFILEenvironment variables inbuild.pytoC:\Users\Publicif the default home profile path contains spaces, resolvingencryptlyexecution crashes on Windows.encryptlysubprocesses to target the cleanworkspace.parentdirectory instead of the repository root (ROOT) to prevent hanging from scanning untracked repository folders.utf-8on launch to avoid UnicodeEncodeErrors.shell=Trueon Windows for NPM tasks execution to avoid FileNotFoundError.Testing
diagnostic\build-6e6ebe98.jsondiagnostic\build-6e6ebe98.logd(5.3 KiB)6f3678ce8859438eab1eChecklist