Skip to content

Commit

Permalink
refactor: enhance Faraday Response with helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 11, 2024
1 parent dbbf99a commit 6528556
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/scalingo/api/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "scalingo/token_holder"
require "scalingo/faraday/response"
require "active_support/core_ext/hash"

module Scalingo
module API
Expand Down
29 changes: 29 additions & 0 deletions lib/scalingo/faraday/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "faraday"
require "faraday/response"

# Some additional methods for Faraday::Response in order to enhance expressiveness
module Faraday
class Response
# @deprecated Use {#success?} instead
def successful?
success?
end

# @deprecated Use {#body} instead
def data
body
end

def client_error?
RaiseError::ClientErrorStatuses.include?(status)
end

def server_error?
RaiseError::ServerErrorStatuses.include?(status)
end

def error?
!success?
end
end
end

0 comments on commit 6528556

Please sign in to comment.