Skip to content

Commit c9df1fb

Browse files
author
unabris
committed
Add option to raise on error requests
1 parent 88be104 commit c9df1fb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/beyond_api/utils.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def handle_response(response, status, respond_with_true: false)
1010
response = sanitize_response(response)
1111
BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
1212
else
13+
error = BeyondApi::Error.new(response)
1314
BeyondApi.logger.error "[Beyond API] #{response}"
14-
BeyondApi::Error.new(response)
15+
BeyondApi.configuration.raise_error_requests ? raise(error) : error
1516
end
1617
end
1718

lib/generators/templates/beyond_api_initializer.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@
2626
# With OpenStructs => response.embeded.products.first.id
2727
# Without OpenStructs => response["embeded"]["products"].first["id"]
2828
# config.object_struct_responses = false
29+
30+
# Configure if the gem should raise on error requests. Setting it to true is
31+
# useful for working with exceptions. Setting it to false will return a
32+
# BeyondApi::Error object with detailed information of the error.
33+
# Default is false.
34+
# config.raise_error_requests = false
2935
end

0 commit comments

Comments
 (0)