Skip to content

Commit c607e35

Browse files
committed
@pcrespov add support_id to error model
1 parent 9e947a4 commit c607e35

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22

33
from common_library.error_codes import create_error_code
4-
from fastapi import status
54
from servicelib.logging_errors import create_troubleshootting_log_kwargs
5+
from servicelib.status_codes_utils import is_5xx_server_error
66
from starlette.requests import Request
77
from starlette.responses import JSONResponse
88

@@ -16,15 +16,17 @@ async def backend_error_handler(request: Request, exc: Exception) -> JSONRespons
1616
assert request # nosec
1717
assert isinstance(exc, BaseBackEndError)
1818
user_error_msg = f"{exc}"
19-
if not exc.status_code >= status.HTTP_500_INTERNAL_SERVER_ERROR:
20-
oec = create_error_code(exc)
21-
user_error_msg += f" [{oec}]"
19+
support_id = None
20+
if is_5xx_server_error(exc.status_code):
21+
support_id = create_error_code(exc)
2222
_logger.exception(
2323
**create_troubleshootting_log_kwargs(
2424
user_error_msg,
2525
error=exc,
26-
error_code=oec,
26+
error_code=support_id,
2727
tip="Unexpected error",
2828
)
2929
)
30-
return create_error_json_response(user_error_msg, status_code=exc.status_code)
30+
return create_error_json_response(
31+
user_error_msg, status_code=exc.status_code, support_id=support_id
32+
)

services/api-server/src/simcore_service_api_server/exceptions/handlers/_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Awaitable, Callable
22
from typing import Any, TypeAlias
33

4+
from common_library.error_codes import ErrorCodeStr
45
from fastapi.encoders import jsonable_encoder
56
from fastapi.requests import Request
67
from fastapi.responses import JSONResponse
@@ -13,13 +14,13 @@
1314

1415

1516
def create_error_json_response(
16-
*errors: Any, status_code: int, **kwargs
17+
*errors: Any, status_code: int, support_id: ErrorCodeStr | None = None, **kwargs
1718
) -> JSONResponse:
1819
"""
1920
Converts errors to Error response model defined in the OAS
2021
"""
2122

22-
error_model = ErrorGet(errors=list(errors))
23+
error_model = ErrorGet(errors=list(errors), support_id=support_id, **kwargs)
2324
return JSONResponse(
2425
content=jsonable_encoder(error_model),
2526
status_code=status_code,

services/api-server/src/simcore_service_api_server/models/schemas/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any
22

3+
from common_library.error_codes import ErrorCodeStr
34
from pydantic import BaseModel, ConfigDict
45

56

@@ -10,6 +11,7 @@ class ErrorGet(BaseModel):
1011
# - https://github.com/ITISFoundation/osparc-simcore/issues/2520
1112
# - https://github.com/ITISFoundation/osparc-simcore/issues/2446
1213
errors: list[Any]
14+
support_id: ErrorCodeStr | None = None
1315

1416
model_config = ConfigDict(
1517
json_schema_extra={

0 commit comments

Comments
 (0)