Skip to content

feat: give each adapter failure its own error code and message [#108] - #133

Open
nisargabd wants to merge 2 commits into
developmentfrom
feat/108-structured-error-responses
Open

nisargabd wants to merge 2 commits into
developmentfrom
feat/108-structured-error-responses

Conversation

@nisargabd

@nisargabd nisargabd commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

Every failure the adapter returns now has its own error code, HTTP status and plain message, in one NACK shape. When a request field is at fault, details.path points to it. Codes come only from the Beckn error enum and the four the adapter already used. No mapping files changed.

Case Before After
Missing context.senderId, receiverId, bppUri or action 400 SCH_INVALID_FORMAT, long sentence 400 CTX_MISSING_FIELD, context.<field> is missing, path $.context.<field>
No context in the body 400 SCH_REQUIRED_FIELD_MISSING, no path same code, context is missing / context must be an object, path $.context
Invalid context.bppUri 400 SCH_INVALID_FORMAT 400 CTX_INVALID_BPP_URI
Unreadable JSON in the cross-network check 400 SCH_INVALID_FORMAT 400 SCH_INVALID_JSON
Action no schema validates 400 SCH_INVALID_FORMAT 400 SCH_ACTION_NOT_SUPPORTED
Schema error path message/items/0/id $.message.items[0].id
Errors from reqpreprocessor bare {"code","message"} body NACK envelope with details.path
Message prefixes BAD Request: ..., Endpoint not found: ... the message alone
Path no module serves plain-text 404 page not found 404 NET_ENTITY_NOT_FOUND, unknown endpoint: <path>
Endpoint not in the routing config 500 404 NET_ENTITY_NOT_FOUND
Action the binding does not serve 400 404 NET_ENTITY_NOT_FOUND
Provider answers 400 502 NET_DOWNSTREAM_UNAVAILABLE 400 BIZ_GENERIC_ERROR, <provider> rejected the request
Provider answers 404 502 NET_DOWNSTREAM_UNAVAILABLE 404 NET_ENTITY_NOT_FOUND, <provider> has no matching record
Provider answers 401/403 502, upstream status text 502 NET_DOWNSTREAM_UNAVAILABLE, <provider> rejected the adapter's credentials
Provider answers 5xx, or cannot be reached 502, upstream error text 502 NET_DOWNSTREAM_UNAVAILABLE, provider named, no URL or host
Provider too slow 502 or 504 NET_DOWNSTREAM_UNAVAILABLE; past the 30s write timeout, connection closed with no answer 504 NET_TIMEOUT, answered before the write timeout
Provider answer not JSON, too large, or one the mapping cannot convert 500 or 502 502 SCH_SCHEMA_ADAPTATION_FAILED
Login token exchange fails 502, token error text 502 NET_DOWNSTREAM_UNAVAILABLE, could not get a login token from <provider>
Adapter setup mistake (credential, mapping file, registry path) 400, 500 or 502, internal text 500 NET_INTERNAL_ERROR, <provider> is not configured on this adapter
Registry down 500 503 NET_DOWNSTREAM_UNAVAILABLE, registry is unavailable
Cross-network forward fails empty 502 NACK: 504 timeout, 502 response refused, 503 unavailable

Errors raised in the core handler keep the 1.x envelope for 1.x requests. reqpreprocessor errors and the unknown-path 404 always use the v2 envelope, because they answer before or without reading context.version.

Why

Weather observation, mandi price, knowledge advisory, POCRA facilities and the PM-KISAN / PM-FBY scheme APIs all answered failures the same way. A caller could not tell a bad request from an unknown record from an upstream being down.

Testing

  • New table test drives a fake provider through every failure above, plus the mapping failure and the deadline, and checks that no message names the provider's URL or host.
  • New test fails if any code outside the allowed set appears in source. Existing tests updated for the new codes and wording.
  • make test, gofmt and go vet pass.
  • Ran 522 scenarios against the local quick-start stack with a fault-injecting stub provider; every response matches the table.

Closes #108

Every capability answered failures the same way, so a caller could not
tell a bad request from an unknown record from a provider being down.
Each failure now has its own code, HTTP status and plain message, in one
NACK shape with details.path where a field is at fault. Codes come only
from the Beckn enum and the four the adapter already used.
@github-actions

Copy link
Copy Markdown

📊 Test Coverage: ✅ Passed — 86% of changed lines covered, min 80%

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🛡️ Trivy security scan (CRITICAL,HIGH,MEDIUM,LOW)

View full run

Go dependencies

Package Severity Installed Fixed in Advisory
go.opentelemetry.io/otel/sdk MEDIUM v1.45.0 1.47.0 CVE-2026-128085
go.opentelemetry.io/otel/sdk/log MEDIUM v0.21.0 1.47.0 CVE-2026-128085
go.opentelemetry.io/otel/trace MEDIUM v1.45.0 1.47.0 CVE-2026-128085

Container image

Package Severity Installed Fixed in Advisory
go.opentelemetry.io/otel/sdk MEDIUM v1.45.0 1.47.0 CVE-2026-128085
go.opentelemetry.io/otel/sdk/log MEDIUM v0.21.0 1.47.0 CVE-2026-128085
go.opentelemetry.io/otel/trace MEDIUM v1.45.0 1.47.0 CVE-2026-128085
stdlib HIGH v1.26.10 1.26.11, 1.27.4 CVE-2026-97054

The constant sat between the payload doc comment and its type, so the comment no longer described the type below it.
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.

1 participant