sdxc-catch-response-middleware

Converts thrown Response objects into router responses in Remix v3 middleware chains.

5|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-catch-response-middleware-sergiodxa
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sdxc-catch-response-middleware
Source: https://github.com/sergiodxa/monorepo/tree/main/.agents/skills/sdxc-catch-response-middleware
Command: npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-catch-response-middleware-sergiodxa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @sdxc/catch-response-middleware.

What problem does it solve? In a Remix v3 router, throwing a Response (like throw redirect(to)) from a deeply nested helper escapes router.fetch() as a rejected promise and surfaces as a 500, because the router only inspects returned values and has no built-in catch. This forces every helper to return error values that each caller must check. ## Core Features & Use Cases - Thrown Response Recovery: A single catchResponse() middleware catches any Response thrown below it in the chain and returns it as the request's response, preserving status and headers. - Guard-Style Authorization: Helpers typed (): User can redirect signed-out requests by throwing instead of returning null for every call site to check. - Middleware Ordering Guidance: Explains placement relative to session, logging, timing, and compression middleware so Set-Cookie headers and response decoration are not lost when a throw unwinds the chain. - Use Case: A route handler calls an auth helper that throws redirect("/login", { status: 303 }); with catchResponse() installed high in the chain, the client receives the 303 redirect instead of a 500 error. ## Quick Start Add the catchResponse middleware to my Remix v3 router so thrown redirects from helpers return proper responses instead of 500 errors.

Frequently Asked Questions about sdxc-catch-response-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle thrown redirects in a Remix v3 router?▼

Add the catchResponse() middleware from @sdxc/catch-response-middleware to the router's middleware chain. It catches any Response thrown below it and returns it as the request's response, so throw redirect(to) works from any helper depth.

Why does throw redirect() return a 500 error in my router?▼

The Remix v3 router only inspects values a middleware or handler returns and has no built-in catch. A thrown Response escapes router.fetch() as a rejected promise and surfaces as a 500 unless a catch middleware is installed above the throw site.

Where should catch middleware go in the middleware chain?▼

Install one instance high in the chain but below every middleware that reads or decorates the response, such as logging, server timing, compression, CORS, and session commits. A throw unwinds the chain, so only middleware above the catch sees the recovered response.

Does catchResponse swallow real errors like TypeError?▼

No, it is not an error boundary. Anything that is not a Response re-throws unchanged, so a TypeError still reaches the runtime with its stack intact. Caught responses are returned as the same instance with status and headers untouched.

Can I scope the catch middleware to a single route?▼

Yes, scoping works because the nearest instance above the throw site catches the Response. However, throws from every other route remain uncaught, so a single high placement is generally preferred.