improvement: extract and surface Xero validation errors on 400 responses#112
Open
maxwellyoung wants to merge 2 commits intoXeroAPI:mainfrom
Open
improvement: extract and surface Xero validation errors on 400 responses#112maxwellyoung wants to merge 2 commits intoXeroAPI:mainfrom
maxwellyoung wants to merge 2 commits intoXeroAPI:mainfrom
Conversation
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
476554e to
cac3eb7
Compare
Contributor
|
@maxwellyoung The |
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
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
awaitinupdateBankTransactionwas already fixed in #106 — this PR focuses on the error formatting improvement.Changes
Enhanced
formatErrorto handle 400 status codesExtracts human-readable validation messages from Xero's nested error response structure:
// Extracts from: error.response.body.Elements[0].ValidationErrors[].MessageThis 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 extractionTest plan