Skip to content

Error handling for non-JSON/malformed API responses #47

Description

@PedGarblue

When the Pusher Push Notifications API returns an error response that is either not valid JSON or doesn't contain the expected error and description properties, the SDK throws a generic exception with the message "An unexpected server error has occurred". This makes debugging difficult as it hides the actual HTTP status code and response details.

catch (\GuzzleHttp\Exception\BadResponseException $e) {
  $response = $e->GetResponse();
  $parsedResponse = json_decode($response->GetBody());
  $badJSON = $parsedResponse === null;
  if (
    $badJSON ||
    !property_exists($parsedResponse, 'error') ||
    !property_exists($parsedResponse, 'description')
  ) {
    throw new \Exception("An unexpected server error has occurred");
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions