generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 175
Closed
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedinternalPRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)
Milestone
Description
Summary
The way the resolve
method works now that we will always return a response:
public async resolve(
event: unknown,
context: Context,
options?: ResolveOptions
): Promise<APIGatewayProxyResult | undefined> {
// ...
const requestContext: RequestContext = {
event,
context,
request,
// this response should be overwritten by the handler, if it isn't
// it means somthing went wrong with the middleware chain
res: new Response('', { status: 500 }),
};
try {
// ...
const middlewareResult = await middleware(
route.params,
requestContext,
() => Promise.resolve()
);
// middleware result takes precedence to allow short-circuiting
const result = middlewareResult ?? requestContext.res;
return handlerResultToProxyResult(result);
} catch (error) {
this.logger.debug(`There was an error processing the request: ${error}`);
const result = await this.handleError(error as Error, {
...requestContext,
scope: options?.scope,
});
return await webResponseToProxyResult(result);
}
}
requestContext.res
is always initialised at the beginning of the function and we will fallback to that response assuming our middleware doesn't short-circuit.
Why is this needed?
Currently when customers use app.resolve
they have to include unnecessary null checks:
export const handler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
const result = app.resolve(event, context);
console.log(result?.body);
return result ?? someDefault;
};
Which area does this relate to?
Event Handler
Solution
No response
Acknowledgment
- This request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedinternalPRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)
Type
Projects
Status
Shipped