Skip to content

improvement: extract and surface Xero validation errors on 400 responses#112

Open
maxwellyoung wants to merge 2 commits intoXeroAPI:mainfrom
maxwellyoung:fix/unhandled-promise-rejection-104
Open

improvement: extract and surface Xero validation errors on 400 responses#112
maxwellyoung wants to merge 2 commits intoXeroAPI:mainfrom
maxwellyoung:fix/unhandled-promise-rejection-104

Conversation

@maxwellyoung
Copy link

@maxwellyoung maxwellyoung commented Jan 19, 2026

Summary

Improves error handling for Xero API validation errors (HTTP 400) by extracting meaningful error messages instead of surfacing raw/generic errors. Related to #104.

Note: The missing await in updateBankTransaction was already fixed in #106 — this PR focuses on the error formatting improvement.

Changes

Enhanced formatError to handle 400 status codes

Extracts human-readable validation messages from Xero's nested error response structure:

// Extracts from: error.response.body.Elements[0].ValidationErrors[].Message

This surfaces clear, actionable error messages (e.g., "Account code is required") instead of generic 400 errors or unhandled promise rejections.

Files Changed

  • src/helpers/format-error.ts: Added 400 status handling with validation error extraction

Test plan

  • Build passes
  • Lint passes
  • Manual test: Send invalid data to trigger 400 error, verify graceful error message instead of crash

This fixes two issues that caused server crashes on API errors:

1. Missing await in updateBankTransaction: The API call was fire-and-forget,
   causing unhandled promise rejections when the Xero API returned errors.
   Now properly awaits and returns the actual response.

2. Enhanced error handling for 400 validation errors: Added extraction of
   Xero validation error messages from Elements[0].ValidationErrors to
   provide meaningful error messages instead of generic failures.

Fixes XeroAPI#104
@maxwellyoung maxwellyoung force-pushed the fix/unhandled-promise-rejection-104 branch from 476554e to cac3eb7 Compare January 20, 2026 01:06
@saleem-aasim-xero
Copy link
Contributor

@maxwellyoung The updateBankTransaction was fixed in a previous PR #106. Can you update the PR title from a fix to an improvement and the description accordingly. Thanks.

@maxwellyoung maxwellyoung changed the title fix: properly await API call and handle validation errors gracefully improvement: extract and surface Xero validation errors on 400 responses Feb 12, 2026
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.

2 participants