Skip to content

Commit c04e0b5

Browse files
committed
Mimic response body parsing of errors in the async client
Fixes #2.
1 parent df5aea8 commit c04e0b5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/groovy/com/mhackner/cloudflare/AsyncCloudFlareClient.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mhackner.cloudflare
22

33
import groovyx.net.http.AsyncHTTPBuilder
44
import groovyx.net.http.ContentType
5+
import groovyx.net.http.HttpResponseException
56
import groovyx.net.http.Method
67

78
import java.util.concurrent.ExecutionException
@@ -16,6 +17,12 @@ class AsyncCloudFlareClient {
1617
AsyncCloudFlareClient(String apiKey, String email, String url = 'https://api.cloudflare.com/client/v4/') {
1718
http = new AsyncHTTPBuilder(uri: url, contentType: ContentType.JSON)
1819
http.headers = ['X-Auth-Key': apiKey, 'X-Auth-Email': email, 'User-Agent': 'HackAttack AsyncCloudFlareClient']
20+
21+
// Mimic the response body parsing of RESTClient
22+
http.handler.failure = { resp, data ->
23+
resp.data = http.handler.success(resp, data)
24+
throw new HttpResponseException(resp)
25+
}
1926
}
2027

2128
Future<List<Map>> getZone(String domain) {

0 commit comments

Comments
 (0)