Skip to content

Conversation

svozza
Copy link
Contributor

@svozza svozza commented Aug 13, 2025

Summary

This is the final PR for the error handling system for event handler and adds decorator functionality as per the RFC in #3500:

class Lambda {
  @app.errorHandler(ZodError)
  public async handleInvalidRequest(error: ZodError) {    
    return {
      statusCode: 400,
      error: 'BadRequest',
      message: error.message
    }
  }

  @app.get('/todos/:todoId')
  public async getTodoById({ params }) {
    const { todoId } = params;
    const todos = await fetch(`https://jsonplaceholder.typicode.com/todos/${todoId}`);
    
    return { todos: await todos.json() }
  }
}

export const handler = async (event, context) =>
  app.resolve(event, context);

Changes

  • Updated the errorHandler, notFound, methodNotAllowed methods to act as decorators
  • Ensured that this is preserved when handleError is called.
  • Unit tests

Issue number: closes #4141


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Aug 13, 2025
@boring-cyborg boring-cyborg bot added event-handler This item relates to the Event Handler Utility tests PRs that add or change tests labels Aug 13, 2025
@svozza svozza force-pushed the event-handler/error-handling-rest-api-decorator branch from 72b1c5d to 82896f2 Compare August 13, 2025 12:57
@svozza svozza force-pushed the event-handler/error-handling-rest-api-decorator branch from 82896f2 to cda64c9 Compare August 13, 2025 13:00
Copy link

@svozza svozza merged commit 562747a into main Aug 13, 2025
34 checks passed
@svozza svozza deleted the event-handler/error-handling-rest-api-decorator branch August 13, 2025 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event-handler This item relates to the Event Handler Utility size/L PRs between 100-499 LOC skip-changelog tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Implement Error Handling System for Event Handler
2 participants