middy v6+ does not re-run the after chain after onError handles an
error, so the regular CORS after hook never fires for error responses.
This dedicated onError step runs after the error handler has set
request.response, ensuring CORS headers are present on error responses.
Apply CORS headers to error responses.
middy v6+ does not re-run the
afterchain afteronErrorhandles an error, so the regular CORSafterhook never fires for error responses. This dedicatedonErrorstep runs after the error handler has setrequest.response, ensuring CORS headers are present on error responses.