Skip to content

Commit

Permalink
review @pcrespov
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Nov 4, 2024
1 parent 2f4d9dc commit 47f0c06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


class ResourceUsageTrackerBaseError(OsparcErrorMixin, Exception):
msg_template = "Resource Usage Tracker unknown error"
msg_template = "Resource usage Tracker Service Error"


class ConfigurationError(ResourceUsageTrackerBaseError):
msg_template = "Resource usage Tracker configuration error"
...


### NotCreatedDBError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import logging
from collections.abc import Callable
from typing import Awaitable

from fastapi import HTTPException, Request, status
from fastapi.encoders import jsonable_encoder
from servicelib.logging_errors import create_troubleshotting_log_kwargs
from servicelib.status_codes_utils import is_5xx_server_error
from starlette.responses import JSONResponse

from ...exceptions.errors import RutNotFoundError

_logger = logging.getLogger(__name__)

async def http_error_handler(_: Request, exc: Exception) -> JSONResponse:

async def http_error_handler(request: Request, exc: Exception) -> JSONResponse:
assert isinstance(exc, HTTPException) # nosec

if is_5xx_server_error(exc.status_code):
_logger.exception(
**create_troubleshotting_log_kwargs(
"Unexpected error happened in the Resource Usage Tracker. Please contact support.",
error=exc,
error_context={
"request": request,
"request.method": f"{request.method}",
},
)
)
return JSONResponse(
content=jsonable_encoder({"errors": [exc.detail]}), status_code=exc.status_code
)
Expand Down

0 comments on commit 47f0c06

Please sign in to comment.