Skip to content

fix: convert makeRequest() to async/await with proper error propagation#852

Open
GaneshPatil7517 wants to merge 2 commits intoHSF:mainfrom
GaneshPatil7517:fix/847-make-request-error-handling
Open

fix: convert makeRequest() to async/await with proper error propagation#852
GaneshPatil7517 wants to merge 2 commits intoHSF:mainfrom
GaneshPatil7517:fix/847-make-request-error-handling

Conversation

@GaneshPatil7517
Copy link
Copy Markdown
Collaborator

Problem
FileLoaderService.makeRequest() had a broken error-reporting pattern:

  1. Always returned false synchronously - the return false at the bottom executed before the fetch() promise ever resolved or rejected
  2. .catch() return value was lost - return true inside .catch() resolved the promise chain, but the synchronous return false had already executed
  3. Unzip failures were uncaught - the inner .then((buf) => this.unzip(buf)) chain for blob responses had no .catch(), so a corrupt zip file caused an unhandled promise rejection
  4. No HTTP error checking -fetch() doesn't throw on 404/500 responses, so HTTP errors were silently treated as successes
  5. Loading state was wrong - EventDataExplorerDialogComponent set this.loading = false immediately (synchronously), not after the request completed

Fix

  • Converted makeRequest() to async/await with a single try/catch wrapping the entire flow (fetch → response parsing → blob/unzip → callback)
  • Added res.ok check to catch HTTP error responses (404, 500, CORS failures)
  • Returns Promise<boolean> - true on error, false on success - matching the original documented contract
  • Converted loadEvent() in FileLoaderService to async so it propagates the promise
  • Converted loadEvent() and loadConfig() in EventDataExplorerDialogComponent to async with await, so:
    • this.error is set after the request completes (not before)
    • this.loading is set to false after the request completes
    • Dialog closes only on actual success

Files changed

  • packages/phoenix-ng/projects/phoenix-ui-components/lib/services/file-loader.service.ts
  • packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/event-data-explorer/event-data-explorer-dialog/event-data-explorer-dialog.component.ts

Testing

  • All 29 test suites / 179 tests pass
  • The pre-existing PHYSLITELoader build error in io-options-dialog.component.ts is unrelated to this change (present on main)- Convert makeRequest() from fire-and-forget fetch to async/await
  • Add HTTP status check (res.ok) for non-throwing fetch failures
  • Wrap entire flow including blob/unzip in try/catch
  • Return Promise so callers can properly await the result
  • Convert loadEvent() in FileLoaderService to async
  • Convert loadEvent()/loadConfig() in EventDataExplorerDialog to async
  • Fix loading state: this.loading now correctly set to false after fetch completes instead of immediately

Resolves #847

- Convert makeRequest() from fire-and-forget fetch to async/await
- Add HTTP status check (res.ok) for non-throwing fetch failures
- Wrap entire flow including blob/unzip in try/catch
- Return Promise<boolean> so callers can properly await the result
- Convert loadEvent() in FileLoaderService to async
- Convert loadEvent()/loadConfig() in EventDataExplorerDialog to async
- Fix loading state: this.loading now correctly set to false after
  fetch completes instead of immediately

Resolves HSF#847
Copilot AI review requested due to automatic review settings March 26, 2026 15:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes error propagation and UI loading-state handling in the phoenix-ui-components file loading pipeline by converting the request flow from “fire-and-forget” promise chains to async/await with centralized error handling.

Changes:

  • Refactored FileLoaderService.makeRequest() to async/await, added res.ok handling, and ensured unzip/parse errors are caught and surfaced via a Promise<boolean> result.
  • Converted FileLoaderService.loadEvent() to return/propagate the async result.
  • Updated EventDataExplorerDialogComponent.loadEvent() / loadConfig() to await results and set loading to false only after completion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/phoenix-ng/projects/phoenix-ui-components/lib/services/file-loader.service.ts Refactors request/unzip flow to async/await with HTTP status checks and boolean error propagation.
packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/event-data-explorer/event-data-explorer-dialog/event-data-explorer-dialog.component.ts Awaits async loaders to correctly update error/loading and only close on successful completion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add urlPath to the HTTP error log for easier debugging
- Use Response.arrayBuffer() directly for blob/zip path instead of
  reading as Blob then converting, avoiding an extra allocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: makeRequest() silently swallows errors and returns before promise resolves

2 participants