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

fix: update REST transport error details #352

Merged
merged 19 commits into from
Dec 1, 2021

Conversation

alicejli
Copy link
Contributor

Currently, if invoking a PHP client library via REST transport (e.g. $newClient = new ServiceClient(['transport' => 'rest']);), the error details displayed are serialized improperly resulting in gibberish (or close to it) error messages.
For instance, the error message currently if invoking a service that a cloud project is not enabled for looks like this:

Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project 372459398382 before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=372459398382 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": 0,
            "data": "type.googleapis.com\/google.rpc.Help"
        },
        {
            "@type": 0,
            "data": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=372459398382"
                }
            ]
        },
        {
            "@type": 1,
            "data": "type.googleapis.com\/google.rpc.ErrorInfo"
        },
        {
            "@type": 1,
            "data": "SERVICE_DISABLED"
        },
        {
            "@type": 1,
            "data": "googleapis.com"
        },
        {
            "@type": 1,
            "data": {
                "service": "translate.googleapis.com",
                "consumer": "projects\/372459398382"
            }
        }
    ]
}

With this fix, the error message will instead look like this:

Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project 372459398382 before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=372459398382 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com\/google.rpc.Help",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=372459398382"
                }
            ]
        },
        {
            "@type": "type.googleapis.com\/google.rpc.ErrorInfo",
            "reason": "SERVICE_DISABLED",
            "domain": "googleapis.com",
            "metadata": {
                "consumer": "projects\/372459398382",
                "service": "translate.googleapis.com"
            }
        }
    ]
}

This technically could be considered a breaking change, so we may need to bundle this change into a new version. However, the current behavior is clearly buggy so not sure if this needs to be considered a breaking change.

@alicejli alicejli requested review from a team as code owners November 29, 2021 20:26
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 29, 2021
Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Just two minor tweaks, and also please add some tests for this.

src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
tests/Tests/Unit/ApiExceptionTest.php Outdated Show resolved Hide resolved
tests/Tests/Unit/ApiExceptionTest.php Show resolved Hide resolved
@bshaffer bshaffer merged commit 80b5330 into googleapis:master Dec 1, 2021
@bshaffer bshaffer mentioned this pull request Dec 1, 2021
@alicejli alicejli deleted the updateRestError branch December 1, 2021 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants