Skip to content

Commit

Permalink
Avoid moving stream pointer when reading response/error body to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevers committed Dec 16, 2021
1 parent 60257cc commit 6b2d97d
Show file tree
Hide file tree
Showing 38 changed files with 1,148 additions and 820 deletions.
120 changes: 70 additions & 50 deletions lib/Api/AplusContentApi.php

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions lib/Api/AuthorizationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ public function getAuthorizationCodeWithHttpInfo($selling_partner_id, $developer
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -412,6 +413,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -422,7 +424,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down
24 changes: 14 additions & 10 deletions lib/Api/CatalogApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ public function getCatalogItemWithHttpInfo($asin, $marketplace_ids, $included_da
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -410,6 +411,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -420,7 +422,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down Expand Up @@ -603,15 +605,16 @@ public function searchCatalogItemsWithHttpInfo($keywords, $marketplace_ids, $inc
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -868,6 +871,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -878,7 +882,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down
36 changes: 21 additions & 15 deletions lib/Api/CatalogItemsV0Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ public function getCatalogItemWithHttpInfo($marketplace_id, $asin)
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -386,6 +387,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -396,7 +398,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down Expand Up @@ -549,15 +551,16 @@ public function listCatalogCategoriesWithHttpInfo($marketplace_id, $asin = null,
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -786,6 +789,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -796,7 +800,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down Expand Up @@ -961,15 +965,16 @@ public function listCatalogItemsWithHttpInfo($marketplace_id, $query = null, $qu
try {
$response = $this->client->send($signedRequest, $options);
$this->writeDebug($response);
$this->writeDebug($response->getBody()->getContents());
$this->writeDebug((string) $response->getBody());
} catch (RequestException $e) {
$body = (string) $e->getResponse()->getBody();
$this->writeDebug($e->getResponse());
$this->writeDebug($e->getResponse()->getBody()->getContents());
$this->writeDebug($body);
throw new ApiException(
"[{$e->getCode()}] {$e->getResponse()->getBody()->getContents()}",
"[{$e->getCode()}] {$body}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody()->getContents() : null
$e->getResponse() ? $body : null
);
}

Expand Down Expand Up @@ -1208,6 +1213,7 @@ function ($response) use ($returnType) {
},
function ($exception) {
$response = $exception->getResponse();
$body = (string) $response->getBody();
$this->writeDebug($response);
$statusCode = $response->getStatusCode();
throw new ApiException(
Expand All @@ -1218,7 +1224,7 @@ function ($exception) {
),
$statusCode,
$response->getHeaders(),
$response->getBody()->getContents()
$body
);
}
);
Expand Down
Loading

0 comments on commit 6b2d97d

Please sign in to comment.