From 0fa943002ebfd4270d0f2a89ca299481fd5e4e6a Mon Sep 17 00:00:00 2001 From: bocasti Date: Mon, 1 Jul 2019 17:48:38 +0200 Subject: [PATCH 1/4] now handle case of an unexpected Mandrill response. Consider as a send error and raise a suitable exception --- .../instance/sendRequest..st | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st index 69bd4c1..b9713bd 100644 --- a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st +++ b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st @@ -4,16 +4,25 @@ sendRequest: aMandrillRequest self prepareRequest: aMandrillRequest. response := ZnClient new url: - (String - streamContents: [ :stream | - stream - nextPutAll: self class baseUrl; - nextPutAll: aMandrillRequest commandUrl ]); + (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')); + (ZnEntity + with: (NeoJSONWriter toStringPretty: aMandrillRequest) + type: ((ZnMimeType main: 'application' sub: 'json') charSet: 'utf-8')); post. - json := (NeoJSONObject fromString: response) first. + 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' \ No newline at end of file + MandrillSendError signal: (json at: 'message') \ No newline at end of file From 4650880050838761c0314f83942e37862e8f79f7 Mon Sep 17 00:00:00 2001 From: bocasti Date: Mon, 1 Jul 2019 17:55:46 +0200 Subject: [PATCH 2/4] test --- .../MandrillClient.class/instance/sendRequest..st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st index b9713bd..c35ff9e 100644 --- a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st +++ b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st @@ -25,4 +25,4 @@ sendRequest: aMandrillRequest nextPutAll: 'Got an unexpected mandrill response: '; nextPutAll: response printString ]) ]. json at: 'code' ifAbsent: [ ^ json ]. - MandrillSendError signal: (json at: 'message') \ No newline at end of file + MandrillSendError signal: (json at: 'message'). \ No newline at end of file From a00741066048275485101442d17d635015ec65cf Mon Sep 17 00:00:00 2001 From: bocasti Date: Tue, 9 Jul 2019 10:04:56 +0200 Subject: [PATCH 3/4] now also handle connection timeout --- .../MandrillClient.class/instance/sendRequest..st | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st index c35ff9e..57b3cdc 100644 --- a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st +++ b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st @@ -2,7 +2,7 @@ as yet unclassified sendRequest: aMandrillRequest | response json | self prepareRequest: aMandrillRequest. - response := ZnClient new + response := [ ZnClient new url: (String streamContents: [ :stream | @@ -13,7 +13,14 @@ sendRequest: aMandrillRequest (ZnEntity with: (NeoJSONWriter toStringPretty: aMandrillRequest) type: ((ZnMimeType main: 'application' sub: 'json') charSet: 'utf-8')); - post. + post ] + on: ConnectionTimedOut + do: [ :ex | + MandrillSendError + signal: + (String + streamContents: + [ :stream | stream nextPutAll: 'Tiemout while connecting to Mandrill server' ]) ]. json := [ (NeoJSONObject fromString: response) first ] on: Error do: [ :ex | @@ -25,4 +32,4 @@ sendRequest: aMandrillRequest nextPutAll: 'Got an unexpected mandrill response: '; nextPutAll: response printString ]) ]. json at: 'code' ifAbsent: [ ^ json ]. - MandrillSendError signal: (json at: 'message'). \ No newline at end of file + MandrillSendError signal: (json at: 'message') \ No newline at end of file From 9737095c26eb281cdd66621a5a1a0f2156f5725c Mon Sep 17 00:00:00 2001 From: bocasti Date: Tue, 9 Jul 2019 11:04:08 +0200 Subject: [PATCH 4/4] changed ConnectionTimeout error handling to NetworkError. --- .../MandrillClient.class/instance/sendRequest..st | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st index 57b3cdc..db778de 100644 --- a/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st +++ b/source/Mandrill-Core.package/MandrillClient.class/instance/sendRequest..st @@ -14,13 +14,15 @@ sendRequest: aMandrillRequest with: (NeoJSONWriter toStringPretty: aMandrillRequest) type: ((ZnMimeType main: 'application' sub: 'json') charSet: 'utf-8')); post ] - on: ConnectionTimedOut + on: NetworkError do: [ :ex | MandrillSendError signal: (String - streamContents: - [ :stream | stream nextPutAll: 'Tiemout while connecting to Mandrill server' ]) ]. + streamContents: [ :stream | + stream + nextPutAll: 'Network error while connecting to Mandrill server: '; + nextPutAll: ex messageText printString ]) ]. json := [ (NeoJSONObject fromString: response) first ] on: Error do: [ :ex |