Skip to content

Custom event_handler exceptions #2221

Closed Answered by leandrodamascena
royassis asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @royassis! Thanks for starting this thread.

The short answer is yes, you can do that by extending the ServiceError class and creating your own exception class, but you don't have to. You already can do this by raising an exception using the ServiceError class and informing the HTTP status code and message you want. Let me give you an example of both situations:

Using the ServiceError class.

from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.event_handler.exceptions import (
    ServiceError,
)
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by royassis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants