Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Modify error and log responses in webserver rest API #443

Open
pcrespov opened this issue Dec 10, 2018 · 4 comments
Open

API: Modify error and log responses in webserver rest API #443

pcrespov opened this issue Dec 10, 2018 · 4 comments
Assignees
Labels
a:api framework api, data schemas, a:webserver issue related to the webserver service

Comments

@pcrespov
Copy link
Member

pcrespov commented Dec 10, 2018

Simplify by removing logger and adding a single message

@pcrespov pcrespov self-assigned this Dec 10, 2018
@pcrespov pcrespov changed the title Modify error response in webserver rest API Modify error and log responses in webserver rest API Dec 13, 2018
@pcrespov pcrespov added the a:infra+ops maintenance of infrastructure or operations (discussed in retro) label Feb 25, 2019
@pcrespov pcrespov added a:webserver issue related to the webserver service a:api framework api, data schemas, labels Sep 19, 2019
@pcrespov
Copy link
Member Author

        details = [
            {
                "loc": ".".join(map(str, e["loc"])),
                "msg": e["msg"],
                "type": e["type"],
            }
            for e in err.errors()
        ]

        resp_payload= {
                    "error": {
                        "msg": reason_msg,
                        "resource": f"{resource}", # optional
                        "details": details, # optional
                    }
                }

@pcrespov pcrespov added this to the Sundae milestone Jul 25, 2023
@pcrespov pcrespov removed the a:infra+ops maintenance of infrastructure or operations (discussed in retro) label Jul 26, 2023
@pcrespov pcrespov modified the milestones: Sundae, Baklava Aug 21, 2023
@pcrespov pcrespov changed the title Modify error and log responses in webserver rest API API: Modify error and log responses in webserver rest API Aug 21, 2023
@pcrespov pcrespov modified the milestones: Baklava, the nameless Sep 13, 2023
@pcrespov
Copy link
Member Author

class OneError(BaseModel):
    msg: str
    type_: str | None = Field(None, alias="type")
    loc: str | None = None


class ManyErrors(BaseModel):
    msg: str
    details: list[OneError] = []

@odeimaiz
Copy link
Member

Current error model

{
  "data": null,
  "error": {
    "logs": [
      {
        "message": "Not sufficient access rights for product",
        "level": "ERROR",
        "logger": "user"
      }
    ],
    "errors": [
      {
        "code": "HTTPForbidden",
        "message": "Not sufficient access rights for product",
        "resource": null,
        "field": null
      }
    ],
    "status": 403,
    "message": "Not sufficient access rights for product"
  }
}

Most of the time it will be

{
  "data": null,
  "error": {
    "msg": "Sorry you do not have sufficient access rights for product"
  }
}

or simply (i.e. w/o data)

{
  "error": {
    "msg": "Sorry you do not have sufficient access rights for product"
  }
}

When the backend has an OEC it will be added as an supportId tag that the front end could present hidden as in

{
  "data": null,
  "error": {
    "msg": "OOps this error was unexpected. we are working on that!",
    "supportId": "OEC:12346789",
  }
}

image

@odeimaiz odeimaiz added this to the Singularity milestone Jan 14, 2025
@odeimaiz odeimaiz assigned odeimaiz and unassigned bisgaard-itis Jan 14, 2025
@matusdrobuliak66
Copy link
Collaborator

matusdrobuliak66 commented Jan 22, 2025

Odei would find it useful on the frontend if the 402 Payment Required error is raised also included additional fields, such as the current amount of credits in the wallet. For example:

{
  "data": null,
  "error": {
    "msg": "Sorry you do not have sufficient number of credits to perform this operation",
    "code": "HTTPPaymentRequired",
    "resource": "wallet",
    "amount": "-80.2",
    "wallet_name": "My Cool Wallet",
  }
}

@pcrespov pcrespov removed this from the Singularity milestone Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:api framework api, data schemas, a:webserver issue related to the webserver service
Projects
None yet
Development

No branches or pull requests

6 participants