-
Notifications
You must be signed in to change notification settings - Fork 124
/
exception_handling.rb
50 lines (47 loc) · 1.32 KB
/
exception_handling.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'bigcommerce'
Bigcommerce.configure do |config|
config.store_hash = ENV['BC_STORE_HASH']
config.client_id = ENV['BC_CLIENT_ID']
config.access_token = ENV['BC_ACCESS_TOKEN']
end
# rubocop:disable MethodLength, Metrics/AbcSize:
def bc_handle_exception
# Below is a list of all the errors we will throw
yield
rescue Bigcommerce::BadRequest => e
puts e.inspect
rescue Bigcommerce::Unauthorized => e
puts e.inspect
rescue Bigcommerce::Forbidden => e
puts e.inspect
rescue Bigcommerce::NotFound => e
puts e.inspect
rescue Bigcommerce::MethodNotAllowed => e
puts e.inspect
rescue Bigcommerce::NotAccepted => e
puts e.inspect
rescue Bigcommerce::TimeOut => e
puts e.inspect
rescue Bigcommerce::ResourceConflict => e
puts e.inspect
rescue Bigcommerce::TooManyRequests => e
puts e.inspect
rescue Bigcommerce::InternalServerError => e
puts e.inspect
rescue Bigcommerce::BadGateway => e
puts e.inspect
rescue Bigcommerce::ServiceUnavailable => e
puts e.inspect
rescue Bigcommerce::GatewayTimeout => e
puts e.inspect
rescue Bigcommerce::BandwidthLimitExceeded => e
puts e.inspect
rescue StandardError => e
puts "Some other Error #{e.inspect}"
end
Bigcommerce::HttpErrors::ERRORS.each do |k, v|
bc_handle_exception do
# This will be your request that you want to protect from exceptions
raise v, k
end
end