Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 1725bd8

Browse files
Merge pull request #25 from stripe/joeydong/logErrors
Add and use helper for logging error messages before returning
2 parents 598d55d + 8740bf6 commit 1725bd8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

web.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
use Rack::Session::EncryptedCookie,
1111
:secret => 'replace_me_with_a_real_secret_key' # Actually use something secret here!
1212

13+
def log_info(message)
14+
puts "\n" + message + "\n\n"
15+
return message
16+
end
17+
1318
get '/' do
1419
status 200
15-
return "Great, your backend is set up. Now you can configure the Stripe example apps to point here."
20+
return log_info("Great, your backend is set up. Now you can configure the Stripe example apps to point here.")
1621
end
1722

1823
post '/ephemeral_keys' do
@@ -24,7 +29,7 @@
2429
)
2530
rescue Stripe::StripeError => e
2631
status 402
27-
return "Error creating ephemeral key: #{e.message}"
32+
return log_info("Error creating ephemeral key: #{e.message}")
2833
end
2934

3035
status 200
@@ -35,7 +40,7 @@
3540
authenticate!
3641
# Get the credit card details submitted
3742
payload = params
38-
if request.content_type.include? 'application/json' and params.empty?
43+
if request.content_type.include? 'application/json' and params.empty?
3944
payload = indifferent_params(JSON.parse(request.body.read))
4045
end
4146

@@ -53,11 +58,11 @@
5358
)
5459
rescue Stripe::StripeError => e
5560
status 402
56-
return "Error creating charge: #{e.message}"
61+
return log_info("Error creating charge: #{e.message}")
5762
end
5863

5964
status 200
60-
return "Charge successfully created"
65+
return log_info("Charge successfully created")
6166
end
6267

6368
def authenticate!
@@ -92,11 +97,11 @@ def authenticate!
9297
)
9398
rescue Stripe::StripeError => e
9499
status 402
95-
return "Error creating charge: #{e.message}"
100+
return log_info("Error creating charge: #{e.message}")
96101
end
97102

98103
status 200
99-
return "Charge successfully created"
104+
return log_info("Charge successfully created")
100105
end
101106

102107
# This endpoint responds to webhooks sent by Stripe. To use it, you'll need
@@ -125,8 +130,7 @@ def authenticate!
125130
:description => "Example Charge"
126131
)
127132
rescue Stripe::StripeError => e
128-
p "Error creating charge: #{e.message}"
129-
return
133+
return log_info("Error creating charge: #{e.message}")
130134
end
131135
# After successfully creating a charge, you should complete your customer's
132136
# order and notify them that their order has been fulfilled (e.g. by sending

0 commit comments

Comments
 (0)