Skip to content

Throwing exception on bad request. #77

Description

@rauwebieten

When the API returns a bad request response, it is not properly handled by the library.

The API returns a JSON with key "Message"

example:

{"Message":"Tag handling parsing failed, please check input.\n\n'undefined entity: line 2, column 17' (at Line: 2, Column: 17)"}

The library assumes a key "message" (lowercase).
See Translator.php method checkStatusCode

$message = '';
try {
    $json = json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
    if (isset($json['message'])) {
        $message .= ", message: {$json['message']}";
    }
    if (isset($json['detail'])) {
        $message .= ", detail: {$json['detail']}";
    }
} catch (\Exception $e) {
    // JSON parsing errors are ignored, and we fall back to the raw response
    $message = ", $content";
}

Thus the details of the error are lost, and this is very hard to debug in our projects.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions