kyleboe / zoom_rb

Ruby REST API Wrapper for zoom.us API
https://developers.zoom.us/docs/api/
MIT License
83 stars 104 forks source link

Error status not mapped properly #464

Closed Sauloxd closed 3 months ago

Sauloxd commented 1 year ago

Hi all! Thanks for you hard work :)

I'm trying to make a "meeting_delete" request to an inexistent ID and I'm seeing a non expected behaviro. What I expect is for the client to raise a Zoom::NotFound error, as the request status_code is 404. As I dig a bit into this repository codebase, I found myself in this part:

def raise_if_error!(response, http_code=200)
        return response unless response.is_a?(Hash) && response.key?('code')

        code = response['code']
        error_hash = build_error(response)

        raise AuthenticationError, error_hash if code == 124
        raise BadRequest, error_hash if code == 400
        raise Unauthorized, error_hash if code == 401
        raise Forbidden, error_hash if code == 403
        raise NotFound, error_hash if code == 404
        raise Conflict, error_hash if code == 409
        raise TooManyRequests, error_hash if code == 429
        raise InternalServerError, error_hash if code == 500
        raise Error.new(error_hash, error_hash)
end

Which should properly map code 404 to NotFound right?

But, the http_response is returning a hash with the following content:

{"code"=>3001, "message"=>"Meeting is not found or has expired."}

And this weird code 3001 is the code mapped in the method raise_if_error! above. I checked and the http_response actually is 404.

So, I guess Zoom has internally different code for different issues, but the regular HTTP status code remains as expected (404 for non existing resources)

Perhaps this mapping of code and Error should be using http_code and not response['code']?

Thanks!

nm commented 4 months ago

I stumbled across the issue as well and created a PR to address it: https://github.com/kyleboe/zoom_rb/pull/473

kyleboe commented 3 months ago

Resolved in #473