rocket-chat icon indicating copy to clipboard operation
rocket-chat copied to clipboard

401 responses not correctly error-handled

Open dulange opened this issue 1 year ago • 0 comments

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):

https://github.com/alekseykuleshov/rocket-chat/blob/66895dce433035efb2d1a17541de492a5170489b/src/Common/Request.php#L125-L139

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.

dulange avatar Jul 11 '23 14:07 dulange