google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

How to get error response in google-cloud-php-translate

Open aaxx255 opened this issue 3 years ago • 1 comments

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 avatar Oct 28 '21 06:10 aaxx255

@aaxx255 would you be able to provide more detail, this is tricky to diagnose with the context provided. Thanks!

dwsupplee avatar Nov 02 '21 16:11 dwsupplee

@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.'"
      }
    ]
  }
}

vishwarajanand avatar May 15 '23 13:05 vishwarajanand