How to use create_exception_response method in localstack

Best Python code snippet using localstack_python

exceptions.py

Source:exceptions.py Github

copy

Full Screen

...45 -------46 Response47 """48 logger.error("Application Exception", exc_info=exc)49 return create_exception_response(exc)50class HTTPExceptionMixin:51 """52 Mixin class for configuring repository objects to raise errors that return an HTTP response.53 Ensure to mixin such that this overwrites the class attributes on54 [`repository.Base`][starlite_bedrock.repository.Base]:55 ```python56 from starlite_bedrock import repository57 class Repo(HTTPExceptionMixin, repository.Base):58 ...59 ```60 """61 base_error_type: type[Exception] = HTTPInternalServerException62 integrity_error_type: type[Exception] = HTTPConflictException63 not_found_error_type: type[Exception] = HTTPNotFoundException

Full Screen

Full Screen

exception_handlers.py

Source:exception_handlers.py Github

copy

Full Screen

...6)7def handle_exceptions(app):8 @app.errorhandler(AlreadyExistsDatabaseException)9 def handle_already_exists_database_exception(e):10 return create_exception_response(HTTPStatus.BAD_REQUEST.value,11 str(e),12 HTTPStatus.BAD_REQUEST.name), HTTPStatus.BAD_REQUEST.value13 @app.errorhandler(AlreadyClaimedDatabaseException)14 def handle_already_claimed_database_exception(e):15 return create_exception_response(HTTPStatus.BAD_REQUEST.value,16 str(e),17 HTTPStatus.BAD_REQUEST.name), HTTPStatus.BAD_REQUEST.value18 @app.errorhandler(NotFoundDatabaseException)19 def handle_not_found_database_exception(e):20 return create_exception_response(HTTPStatus.NOT_FOUND.value,21 str(e),22 HTTPStatus.NOT_FOUND.name), HTTPStatus.NOT_FOUND.value23 @app.errorhandler(Exception)24 def handle_exception(e):25 return create_exception_response(HTTPStatus.INTERNAL_SERVER_ERROR.value,26 f"Internal server error. {str(e)}",27 HTTPStatus.INTERNAL_SERVER_ERROR.name), HTTPStatus.INTERNAL_SERVER_ERROR.value28def create_exception_response(status_code, message, status_name):...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...9class ExceptionResponseContent(BaseModel):10 detail: Optional[str]11 extra: Optional[Union[Dict[str, Any], List[Any]]] = None12 status_code: int = HTTP_500_INTERNAL_SERVER_ERROR13def create_exception_response(exc: Exception) -> Response:14 """Constructs a response from an exception.15 For instances of either `starlite.exceptions.HTTPException` or `starlette.exceptions.HTTPException` the response16 status code is drawn from the exception, otherwise response status is `HTTP_500_INTERNAL_SERVER_ERROR`.17 Args:18 exc (Exception): Any exception.19 Returns:20 Response: HTTP response constructed from exception details.21 """22 if isinstance(exc, (HTTPException, StarletteHTTPException)):23 content = ExceptionResponseContent(detail=exc.detail, status_code=exc.status_code)24 if isinstance(exc, HTTPException):25 content.extra = exc.extra26 else:27 content = ExceptionResponseContent(detail=repr(exc))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful