Skip to content

fix(customers): include error field on POST 400s - #1128

Merged
khaira777 merged 1 commit into
mainfrom
fm/flocafe-issue-1093-r1
Oct 14, 2026
Merged

khaira777 merged 1 commit into
mainfrom
fm/flocafe-issue-1093-r1

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Verify and implement the surgical fix for FreeOpenSourcePOS/FloCafe issue #1093 ("POST /api/customers validation errors omit standard error field"): in main/routes/customers.ts, include the standard error field alongside message in POST /api/customers error responses so callers inspecting either error or message receive a consistent payload. Deliver via the no-mistakes pipeline as its own PR with Fixes #1093 in the PR summary.

What Changed

  • Included the standard error field alongside message in POST /api/customers 400 (missing name, invalid phone), 409 (duplicate phone), and 500 error responses in main/routes/customers.ts.
  • Added assertions in tests/diagnostics-feature-coverage.test.ts verifying that both error and message fields are returned for duplicate phone, empty name, and invalid phone responses on POST /api/customers.

Fixes #1093

Risk Assessment

✅ Low: Surgical change adding the standard error field alongside message in POST /api/customers error responses, backed by HTTP integration test assertions.

Testing

Ran the diagnostics feature coverage and customer auth regression suites and drove a live Express API server against an isolated SQLite database for blank name (400), invalid phone (400), duplicate phone (409), and database write failure (500) on POST /api/customers, recording the HTTP response payloads to post-customers-error-responses.json; no visual screenshot was captured because this change is backend API-only with no UI surface change, and all checks passed.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Submitting POST /api/customers with a blank name returns HTTP 400 with both error and message set to 'Name is required' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Submitting POST /api/customers with an invalid phone number returns HTTP 400 with matching error and message fields ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Submitting POST /api/customers with a phone number already belonging to an active customer returns HTTP 409 with both error and message set to 'Customer with this phone already exists' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Triggering an unexpected database failure during POST /api/customers returns HTTP 500 with both error and message set to 'Failed to create customer' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Evidence: POST /api/customers live HTTP error response payloads

{ "scenario_1_empty_name": { "status": 400, "body": { "error": "Name is required", "message": "Name is required" } }, "scenario_2_invalid_phone": { "status": 400, "body": { "error": "Phone number is not valid. Use international format (e.g. +919876543210).", "message": "Phone number is not valid. Use international format (e.g. +919876543210)." } }, "scenario_3_duplicate_phone": { "initial_create_status": 201, "duplicate_status": 409, "duplicate_body": { "error": "Customer with this phone already exists", "message": "Customer with this phone already exists" } }, "scenario_4_database_failure_500": { "status": 500, "body": { "error": "Failed to create customer", "message": "Failed to create customer" } } }

{
  "scenario_1_empty_name": {
    "status": 400,
    "body": {
      "error": "Name is required",
      "message": "Name is required"
    }
  },
  "scenario_2_invalid_phone": {
    "status": 400,
    "body": {
      "error": "Phone number is not valid. Use international format (e.g. +919876543210).",
      "message": "Phone number is not valid. Use international format (e.g. +919876543210)."
    }
  },
  "scenario_3_duplicate_phone": {
    "initial_create_status": 201,
    "duplicate_status": 409,
    "duplicate_body": {
      "error": "Customer with this phone already exists",
      "message": "Customer with this phone already exists"
    }
  },
  "scenario_4_database_failure_500": {
    "status": 500,
    "body": {
      "error": "Failed to create customer",
      "message": "Failed to create customer"
    }
  }
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Submitting POST /api/customers with a blank name returns HTTP 400 with both error and message set to 'Name is required' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Submitting POST /api/customers with an invalid phone number returns HTTP 400 with matching error and message fields ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Submitting POST /api/customers with a phone number already belonging to an active customer returns HTTP 409 with both error and message set to 'Customer with this phone already exists' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
Triggering an unexpected database failure during POST /api/customers returns HTTP 500 with both error and message set to 'Failed to create customer' ✅ pass live ~/.no-mistakes/evidence/01M4VHBKGF3K669DWNQ9M9JPB1/post-customers-error-responses.json
  • node tests/run-electron-node-test.cjs tests/diagnostics-feature-coverage.test.ts
  • npm run test:customer-auth
  • ELECTRON_RUN_AS_NODE=1 ./node_modules/.bin/electron -r ts-node/register/transpile-only -e '<live POST /api/customers scenario runner>'
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a1488cea-492f-4beb-80c7-dd3813f5ef2a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds error field to customer creation API responses.

The PR appears safe to merge, with a non-blocking test gap for the 500 response.

Findings

  1. P2 500 response lacks test coverage ▶

Summary

Adds error alongside the existing message in four POST /api/customers error responses.

  • Customer creation errors return matching error and message fields.

Reviews (1) · Last reviewed commit: "fix(customers): include error field on P..." · Reviewed by Greptile

Comment thread main/routes/customers.ts Resolved
@khaira777 khaira777 changed the title fix: include error field in POST /api/customers error responses fix(customers): include error field on POST 400s Oct 13, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

Reviewed the implementation against the existing customer API contract.

The fix looks correct. Adding error alongside the existing message field preserves backward compatibility while allowing standard API error handlers to work. The new tests cover the main 400 and 409 responses.

One optional improvement: add a permanent regression test for the updated 500 response, which is currently covered by recorded live validation but not the committed tests.

No blocking changes requested. Ready to merge once the required CI checks pass.

@khaira777
khaira777 force-pushed the fm/flocafe-issue-1093-r1 branch from 65add4d to 8816afa Compare October 13, 2026 23:57
@khaira777
khaira777 enabled auto-merge (squash) October 13, 2026 23:57
@khaira777
khaira777 merged commit 6fef8a0 into main Oct 14, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-issue-1093-r1 branch October 14, 2026 00:11
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(api): standardize error response payload key to { error } across customer routes

1 participant