Class: Mifiel::Base
- Inherits:
-
Flexirest::Base
- Object
- Flexirest::Base
- Mifiel::Base
show all
- Defined in:
- lib/mifiel/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.process_request(path, mthd, payload: nil, type: false) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/mifiel/base.rb', line 18
def self.process_request(path, mthd, payload: nil, type: false)
url = "#{Mifiel.config.base_url}/#{path.gsub(%r{^/}, '')}"
options = { request_body_type: type }
options[:plain] = true if type == :plain
_request(
url,
mthd,
payload,
options,
)
end
|
Instance Method Details
#rescue_errors(_name, response) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/mifiel/base.rb', line 7
def rescue_errors(_name, response)
case response.status
when (400..499)
result = JSON.parse(response.body)
message = result['errors'] || [result['error']]
raise BadRequestError, message.to_a.join(', ')
when (500..599)
raise ServerError, "Could not process your request: status #{response.status}"
end
end
|