Pyjo.GCP.Error - Error of an API of Google Cloud

from Pyjo.GCP.Call import Call
from Pyjo.GCP.Client import Client
from Pyjo.GCP.Error import Error

try:
    Client(service='storage').call(Call('GET', '/storage/v1/b/mybucket/o/missing'))
except Error as e:
    print(e.code, e.status, e.reason, e.message)

Pyjo.GCP.Error is the error that an API of Google Cloud responds with, which a call of Pyjo.GCP.Client raises, or rejects its promise with, as Pyjo.GCP.Call reads it of the response, the JSON of google.rpc.Status in error:

{
  "error": {
    "code": 403,
    "message": "Cloud Storage API has not been used in project 123 before or it is disabled.",
    "status": "PERMISSION_DENIED",
    "details": [{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "SERVICE_DISABLED"}]
  }
}

and the older format of Cloud Storage and others, without status and with the reason in errors:

{"error": {"code": 404, "message": "No such object: mybucket/missing",
           "errors": [{"message": "No such object: mybucket/missing", "domain": "global", "reason": "notFound"}]}}

See also

Pyjo.GCP.Client, Pyjo.GCP.Call, Pyjo.Exception, https://google.aip.dev/193.

Classes

exception Pyjo.GCP.Error.Pyjo_GCP_Error(code: int | None, message: str = '', *, status: str | None = None, reason: str | None = None, details: list[Any] | None = None, tx: Pyjo_Transaction_HTTP | None = None)[source]

Pyjo.GCP.Error inherits all attributes and methods from Pyjo.Exception and implements the following new ones.

__init__(code: int | None, message: str = '', *, status: str | None = None, reason: str | None = None, details: list[Any] | None = None, tx: Pyjo_Transaction_HTTP | None = None) → None[source]
e = Pyjo.GCP.Error.new(404, 'No such object: mybucket/missing', status='NOT_FOUND', reason='notFound')

Construct a new Pyjo.GCP.Error object, whose message is the code, the status and the message of Google Cloud, as 404 NOT_FOUND: No such object: mybucket/missing.

code
code = e.code

The code of the error, the status of HTTP, as 404, or None of a response without one.

details: list[Any]
details = e.details

The details of the error, of details, as google.rpc.ErrorInfo, or an empty list.

reason
reason = e.reason

The reason of the error, of reason of errors, as notFound, or of the detail google.rpc.ErrorInfo, as SERVICE_DISABLED, or None.

status
status = e.status

The status of google.rpc.Code, as NOT_FOUND, or None of an API that has none, as Cloud Storage.

tx
tx = e.tx

The transaction of the request and its response, or None.