Skip to content

Conversation

@maxwellyoung
Copy link

@maxwellyoung maxwellyoung commented Jan 19, 2026

Summary

Fixes #104 - The MCP server crashed on Xero API validation errors (HTTP 400) due to unhandled promise rejections.

Root Causes & Fixes

1. Missing await in updateBankTransaction

The API call at line 49 was not awaited, causing promises to be fire-and-forget:

// Before (bug)
xeroClient.accountingApi.updateBankTransaction(...);
return bankTransaction;  // Returns input, not actual response

// After (fix)
const response = await xeroClient.accountingApi.updateBankTransaction(...);
return response.body.bankTransactions?.[0];  // Returns actual API response

2. No extraction of Xero validation errors

Enhanced formatError to handle 400 status codes and extract meaningful validation messages from Xero's error response structure:

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

Changes

  • src/handlers/update-xero-bank-transaction.handler.ts: Added missing await, return actual API response
  • 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
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.

Unhandled Promise Rejection Crashes Server on Xero API Validation Errors

1 participant