Skip to content

Commit

Permalink
Merge pull request #3 from noha/refine-error-handling-when-sending-re…
Browse files Browse the repository at this point in the history
…quest

Refine error handling when sending request
  • Loading branch information
noha authored Jul 9, 2019
2 parents c41c2c6 + 9737095 commit ac10e37
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@ as yet unclassified
sendRequest: aMandrillRequest
| response json |
self prepareRequest: aMandrillRequest.
response := ZnClient new
response := [ ZnClient new
url:
(String
(String
streamContents: [ :stream |
stream
nextPutAll: self class baseUrl;
nextPutAll: aMandrillRequest commandUrl ]);
entity:
(ZnEntity
with: (NeoJSONWriter toStringPretty: aMandrillRequest)
type: ((ZnMimeType main: 'application' sub: 'json') charSet: 'utf-8'));
post ]
on: NetworkError
do: [ :ex |
MandrillSendError
signal:
(String
streamContents: [ :stream |
stream
nextPutAll: self class baseUrl;
nextPutAll: aMandrillRequest commandUrl ]);
entity:
(ZnEntity
with: (NeoJSONWriter toStringPretty: aMandrillRequest)
type: ((ZnMimeType main: 'application' sub: 'json') charSet: 'utf-8'));
post.
json := (NeoJSONObject fromString: response) first.
nextPutAll: 'Network error while connecting to Mandrill server: ';
nextPutAll: ex messageText printString ]) ].
json := [ (NeoJSONObject fromString: response) first ]
on: Error
do: [ :ex |
MandrillSendError
signal:
(String
streamContents: [ :stream |
stream
nextPutAll: 'Got an unexpected mandrill response: ';
nextPutAll: response printString ]) ].
json at: 'code' ifAbsent: [ ^ json ].
MandrillSendError signal: json at: 'message'
MandrillSendError signal: (json at: 'message')

0 comments on commit ac10e37

Please sign in to comment.