Skip to content

Commit

Permalink
Add Unprocessable error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ondra-m committed Aug 7, 2015
1 parent 11f0e47 commit 4c0395e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/gitlab/error.rb
Expand Up @@ -27,6 +27,9 @@ class MethodNotAllowed < Error; end
# Raised when API endpoint returns the HTTP status code 409.
class Conflict < Error; end

# Raised when API endpoint returns the HTTP status code 422.
class Unprocessable < Error; end

# Raised when API endpoint returns the HTTP status code 500.
class InternalServerError < Error; end

Expand Down
6 changes: 5 additions & 1 deletion lib/gitlab/request.rb
Expand Up @@ -73,6 +73,7 @@ def validate(response)
when 404; raise Error::NotFound.new error_message(response)
when 405; raise Error::MethodNotAllowed.new error_message(response)
when 409; raise Error::Conflict.new error_message(response)
when 422; raise Error::Unprocessable.new error_message(response)
when 500; raise Error::InternalServerError.new error_message(response)
when 502; raise Error::BadGateway.new error_message(response)
when 503; raise Error::ServiceUnavailable.new error_message(response)
Expand Down Expand Up @@ -113,8 +114,11 @@ def set_httparty_config(options)
end

def error_message(response)
parsed_response = response.parsed_response
message = parsed_response.message || parsed_response.error

"Server responded with code #{response.code}, message: " \
"#{handle_error(response.parsed_response.message)}. " \
"#{handle_error(message)}. " \
"Request URI: #{response.request.base_uri}#{response.request.path}"
end

Expand Down

0 comments on commit 4c0395e

Please sign in to comment.