Skip to content

[PRD-020] 0.1.1 — MoleculerClientError code → HTTP status mapping - #3

Merged
explosivebit merged 2 commits into
devfrom
fix/client-error-code-mapping
Apr 9, 2026
Merged

explosivebit merged 2 commits into
devfrom
fix/client-error-code-mapping

Conversation

@explosivebit

Copy link
Copy Markdown
Contributor

Summary

Companion release moleculerpy-web 0.1.1 for the PRD-020 bug closure sprint in the moleculerpy core repo (PR MoleculerPy/moleculerpy#46, shipping as v0.14.22).

Closes KNOWN-ISSUES #19: `moleculer_error_to_http` now honours `MoleculerClientError.code` and dispatches to the matching typed gateway error (`UnauthorizedError` for 401, `ForbiddenError` for 403, `NotFoundError` for 404). Previously every `MoleculerClientError` funnelled into `BadRequestError(400)` regardless of its code, masking auth failures behind a misleading "Bad Request".

Commits

Commit Scope
`1c95efe` Fix: `moleculer_error_to_http` honours `err.code` for 4xx mapping + 3 unit regression tests
`fa4cad7` Release prep: version 0.1.0 → 0.1.1 + CHANGELOG

Evidence

Gate Result
`ruff format` + `ruff check` + `mypy moleculerpy_web/` all clean
Unit tests 380 passed (was 377 — +3 regression: `test_moleculer_client_error_401/403/404_maps_to_*`)
Demo validation `demo_web` `test_client_error_401/403/404` all PASS with exact status match (was `in (400, 401)` lenient)
Counterfactual Revert `moleculer_error_to_http` to unconditional `BadRequestError` → all 3 demo assertions fail with `status=400` — proven during sprint
Shadowing check Demo auditor verified `ServiceNotFoundError` (inherits from `MoleculerRetryableError`, not `MoleculerClientError`) does NOT shadow the 404 branch — control flow reaches the new numeric code path cleanly

Test plan

  • Unit: `/Users/explosovebit/Work/MoleculerPy/moleculerpy/.venv/bin/pytest tests/unit/` → 380/380
  • Integration via core demo: `demo_web` all 13 tests pass including the 3 new exact-match tests
  • Counterfactual proof of regression-guard strength

Refs

🤖 Generated with Claude Code

explosivebit and others added 2 commits April 8, 2026 23:03
Close KNOWN-ISSUES #19. Previously every MoleculerClientError funnelled
into BadRequestError(400) regardless of the underlying HTTP semantics, so
auth failures raised inside service actions surfaced as "400 Bad Request"
at the gateway — making scripted clients and middlewares unable to
distinguish missing credentials from malformed payloads.

moleculer_error_to_http now inspects err.code and dispatches to the
matching typed gateway error:
  * code=401 → UnauthorizedError (HTTP 401)
  * code=403 → ForbiddenError (HTTP 403)
  * code=404 → NotFoundError (HTTP 404)
  * anything else → BadRequestError (HTTP 400, unchanged fallback)

All four UnauthorizedError / ForbiddenError / NotFoundError classes
already existed in errors.py, so this is a pure dispatch fix with no new
public surface.

Evidence:
  * tests/unit/test_errors.py — 3 new regression tests
    (test_moleculer_client_error_401_maps_to_unauthorized, _403_maps_to_forbidden,
    _404_maps_to_not_found) plus the pre-existing default-to-400 test
    stays green so backwards compatibility is preserved
  * 380/380 tests pass (+3), coverage held at 94%

Refs: PRD-020, KNOWN-ISSUES.md #19
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Companion release for moleculerpy 0.14.22 (PRD-020 bug closure sprint).
Ships the #19 fix committed in 1c95efe (moleculer_error_to_http honours
MoleculerClientError.code for 401/403/404 instead of funnelling every
client error into HTTP 400).

CHANGELOG entry documents the fix + counterfactual evidence (reverting
moleculer_error_to_http makes demo_web test_client_error_401/403/404
all fail with status=400).

Refs: PRD-020, KNOWN-ISSUES.md #19
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@explosivebit
explosivebit merged commit 676d3d4 into dev Apr 9, 2026
8 checks passed
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