Skip to content

feat: Handle preprocess errors - #100

Merged
javiergarea merged 1 commit into
mainfrom
feat/handle-preprocess-errors
Jul 17, 2026
Merged

feat: Handle preprocess errors#100
javiergarea merged 1 commit into
mainfrom
feat/handle-preprocess-errors

Conversation

@josecriane

@josecriane josecriane commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Reworks erf_router:handle/2 so that requests failing at the preprocess stage still flow through the postprocess middlewares and postprocess/1, instead of returning the raw 400 response early.

Motivation

Previously, when preprocess/1 failed (e.g. an unreadable request), handle/2 returned the 400 Bad Request response directly, bypassing apply_postprocess_middlewares/3 and postprocess/1. This caused two problems:

  • Postprocess middlewares (logging, metrics, header injection, etc.) never ran for malformed requests, leaving a gap in observability and inconsistent response handling.
  • The error response was returned as-is, with no chance to be handled by the postprocessing pipeline, so it could end up not matching the error shape defined in the OpenAPI spec.

Changes

  • Moved the preprocess/1 case so it only computes the {InitialResponse, InitialRequest} pair.
  • On preprocess error, the 400 response is paired with the original RawRequest ({ResponseError, RawRequest}) so downstream stages have a valid request to work with.
  • apply_postprocess_middlewares/3 and postprocess/1 now run unconditionally for both the success and error paths.

@github-project-automation github-project-automation Bot moved this to 📑 TODO in erf Jul 17, 2026
@josecriane
josecriane force-pushed the feat/handle-preprocess-errors branch from 5948d6f to d75ea2d Compare July 17, 2026 10:06

@javiergarea javiergarea left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@github-project-automation github-project-automation Bot moved this from 📑 TODO to :shipit: In Progress in erf Jul 17, 2026
@javiergarea
javiergarea merged commit 173eaa8 into main Jul 17, 2026
2 checks passed
@javiergarea
javiergarea deleted the feat/handle-preprocess-errors branch July 17, 2026 10:46
@github-project-automation github-project-automation Bot moved this from :shipit: In Progress to 🎉 Done in erf Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

2 participants