google-cloud-php
google-cloud-php copied to clipboard
How to get error response in google-cloud-php-translate
Remind me when my balance is insufficient, I need to get this error think you.
"error": { "code": 403, "message": "xxx", "errors": [ { "message": "xxx", "domain": "xxx", "reason": "xxxx" } ] } }
@aaxx255 would you be able to provide more detail, this is tricky to diagnose with the context provided. Thanks!
@aaxx255 Sorry to get back to this issue so late.
I changed the target language to an invalid code in message, (ex - {"target":"hn","q":["Hello."]}
) and wrapped the logic around a try/catch block. With the caught \Exception
, I can see its details like you formatted with this code snippet: $ex->getMessage()
.
{
"error": {
"code": 400,
"message": "Invalid Value",
"errors": [
{
"message": "Invalid Value",
"domain": "global",
"reason": "invalid",
"debugInfo": "Target language is not set to a valid language code:hn"
}
],
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "target",
"description": "Target language: hn"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"detail": "InternalError: Name: TARGET_LANGUAGE_INVALID Code: 13 Message: 'Target language is invalid.'"
}
]
}
}