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

CloudinaryException is too vague #338

Open
benjaminoakes opened this issue Jun 18, 2019 · 3 comments
Open

CloudinaryException is too vague #338

benjaminoakes opened this issue Jun 18, 2019 · 3 comments

Comments

@benjaminoakes
Copy link

benjaminoakes commented Jun 18, 2019

We've seen messages like Resource not found and Error in loading, which we'd like to handle as generic HTTP client errors (400-499). Unfortunately, we have to rescue the CloudinaryException, check its error message, and then determine what should be done.

I would propose having more than one exception class to make it possible for us to rescue something like Cloudinary::HttpClientError to ignore errors like HTTP 403 (Forbidden), 404 (Not Found), 408 (Request Timeout), etc.

One way to do this would be to add class Cloudinary::HttpClientError < CloudinaryException; end and then use that error for the cases that represent HTTP 400-499.

@nilbus
Copy link

nilbus commented Jun 18, 2019

👍 I like the idea of segmenting these errors into ones that should be retriable and not. Sometimes a CloudinaryException can represent a transient network error or downtime event that should be retried, like these:

raise CloudinaryException, "Server returned unexpected status code - #{response.code} - #{response.body}" unless [200, 400, 401, 403, 404, 500].include?(response.code)
begin
result = Cloudinary::Utils.json_decode(response.body)
rescue => e
# Error is parsing json
raise CloudinaryException, "Error parsing server response (#{response.code}) - #{response.body}. Got - #{e}"
end
if result["error"]
if return_error
result["error"]["http_code"] = response.code
else
raise CloudinaryException, result["error"]["message"]

@nilbus
Copy link

nilbus commented Jun 18, 2019

For backward compatibility, the specific errors raised can both be subclasses of CloudinaryException.

@roeeba
Copy link
Collaborator

roeeba commented Jun 20, 2019

Hi @benjaminoakes, @nilbus. Thank you for your feedback! I'm going to pass it forward to our engineers to review. We'll update here with any updates.

@tocker tocker removed their assignment Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants