Skip to content

Commit 785c772

Browse files
fern-supportjsklan
andauthored
update readme (#199)
Co-authored-by: jsklan <[email protected]>
1 parent 5dc7216 commit 785c772

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ client = SquareLegacy::Client.new(
105105
```
106106
4. Gradually migrate over to the new SDK by importing it from the `'square'` import.
107107

108+
## Environments
109+
110+
This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
111+
112+
### Environments
113+
```ruby
114+
require "square"
115+
116+
client = Square::Client.new(
117+
base_url: Square::Environment::PRODUCTION
118+
)
119+
```
120+
121+
### Custom URL
122+
```ruby
123+
require "square"
124+
125+
client = Square::Client.new(
126+
base_url: "https://custom-staging.com"
127+
)
128+
```
129+
108130
## Request And Response Types
109131

110132
The SDK exports all request and response types as Ruby classes. Simply require them with the
@@ -119,20 +141,29 @@ request = Square::CreateMobileAuthorizationCodeRequest.new(
119141
)
120142
```
121143

122-
## Exception Handling
144+
## Errors
123145

124-
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
125-
will be raised.
146+
Failed API calls will raise errors that can be rescued from granularly.
126147

127148
```ruby
128-
require 'square'
149+
require "square"
150+
151+
client = Square::Client.new(
152+
base_url: Square::Environment::PRODUCTION
153+
)
129154

130155
begin
131-
response = client.payments.create(...)
132-
rescue Square::ApiError => e
133-
puts "Status Code: #{e.status_code}"
134-
puts "Message: #{e.message}"
135-
puts "Body: #{e.body}"
156+
result = client.payments.create
157+
rescue Square::Errors::TimeoutError
158+
puts "API didn't respond before our timeout elapsed"
159+
rescue Square::Errors::ServiceUnavailableError
160+
puts "API returned status 503, is probably overloaded, try again later"
161+
rescue Square::Errors::ServerError
162+
puts "API returned some other 5xx status, this is probably a bug"
163+
rescue Square::Errors::ResponseError => e
164+
puts "API returned an unexpected status other than 5xx: #{e.code} {e.message}"
165+
rescue Square::Errors::ApiError => e
166+
puts "Some other error occurred when calling the API: {e.message}"
136167
end
137168
```
138169

0 commit comments

Comments
 (0)