Skip to content

Handle LetterXpress validation errors and require national shipping for registered mail - #90

Merged
emuuu merged 1 commit into
mainfrom
fix/letterxpress-error-responses
Oct 23, 2026
Merged

emuuu merged 1 commit into
mainfrom
fix/letterxpress-error-responses

Conversation

@emuuu

@emuuu emuuu commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Fixed: LetterXpress v3 returns validation errors with an object-valued message (field name → array of messages), e.g. {"status":400,"message":{"letter.registered":["The letter.registered field is prohibited when letter.specification.shipping is auto."]}}. TryParseErrorDetail called GetString() on it, so the client threw InvalidOperationException instead of LetterXpressException, losing status code and reason. Object messages are now flattened to field: message (joined with ; ), arrays are joined, anything else falls back to the raw body. Parsing never throws.
  • Fixed: the same shape on an HTTP 200 response with an application-level error status failed deserialization (Failed to deserialize LetterXpress response., no status code). LxResponse.Message is no longer mapped; the message is read via the error helper.
  • Behavior change: registered mail now requires ShippingType.National. LetterXpress rejects it for Auto (the default) as well as International; the client throws ArgumentException before sending and never switches the shipping type implicitly. UpdatePrintJobAsync applies the check when an update sets both Registered and Shipping.
  • XML docs, LetterXpress docs page, generated API docs and CHANGELOG updated.

Tests

  • LetterXpress.Letters.Tests: 38 → 61 (error helper: string/object/array message, error instead of message, non-JSON, empty body, JSON without both fields, undecodable strings; client: HTTP 400 validation error → LetterXpressException with status 400 and flattened message, body-level validation error, registered + Auto/default/International validation). Green on net10.0 locally, CI covers net8.0/net9.0.

…or registered mail

- Parse object- and array-valued "message"/"error" fields in LetterXpress error bodies
  (flattened to "field: message", joined with "; "); parsing never throws
- Always surface API rejections as LetterXpressException with status code, including
  HTTP 200 responses with an application-level error and an object-valued message
- Reject registered mail unless shipping is National (Auto is rejected by the API too);
  apply the same check in UpdatePrintJobAsync when both values are set
- Update XML docs, LetterXpress docs page, regenerated API docs and CHANGELOG
@emuuu
emuuu merged commit 5e51456 into main Oct 23, 2026
5 checks passed
@emuuu
emuuu deleted the fix/letterxpress-error-responses branch October 23, 2026 10:55
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