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

401 responses not correctly error-handled #29

Open
dulange opened this issue Jul 11, 2023 · 0 comments
Open

401 responses not correctly error-handled #29

dulange opened this issue Jul 11, 2023 · 0 comments

Comments

@dulange
Copy link

dulange commented Jul 11, 2023

When the Rocket.Chat REST API responds with 401 due to invalid authentication, the response looks like this (prettified):

{
  "status": "error",
  "message": "You must be logged in to do this."
}

However, the error handling in the Request::send method is a mere success handler (literally, by checking if the JSON response has a success property with a falsy value):

static::$response = @json_decode($responseBody);
static::$responseCode = $responseCode;
static::$responseUrl = (!empty($headersRedirect)) ? $headersRedirect[count($headersRedirect) - 1] : null;
if (isset(static::$response->success) && (!static::$response->success)) {
if (isset(static::$response->error)) {
static::setError(static::$response->error);
} else {
static::setError("Unknown error occurred in api");
}
static::$success = false;
}
return ((static::$responseCode >= 200) && (static::$responseCode < 300));

The final bool return value of the method, (static::$responseCode >= 200) && (static::$responseCode < 300), could handle this case but Request::sends return value appears to be unused elsewhere in the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant