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.Errorinherits all attributes and methods fromPyjo.Exceptionand 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.Errorobject, whosemessageis the code, the status and the message of Google Cloud, as404 NOT_FOUND: No such object: mybucket/missing.
- code¶
code = e.code
The code of the error, the status of HTTP, as
404, orNoneof a response without one.
- details: list[Any]¶
details = e.details
The details of the error, of
details, asgoogle.rpc.ErrorInfo, or an empty list.
- reason¶
reason = e.reason
The reason of the error, of
reasonoferrors, asnotFound, or of the detailgoogle.rpc.ErrorInfo, asSERVICE_DISABLED, orNone.
- status¶
status = e.status
The status of
google.rpc.Code, asNOT_FOUND, orNoneof an API that has none, as Cloud Storage.
- tx¶
tx = e.tx
The transaction of the request and its response, or
None.