Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rbairwell committed Feb 8, 2019
1 parent b4c56b4 commit 31921e4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.2 - 2019.02-8
## 1.0.3 - 2019.02-08
## Fixed
More logging data.

## 1.0.2 - 2019.02-08
## Fixed
Version number in composer.json

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "silktide/craft-silktide",
"description": "Integrate Silktide with Craft",
"version" : "1.0.3",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down
2 changes: 1 addition & 1 deletion src/CraftSilktide.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Integrate Silktide with Craft
*
* @link https://www.silktide.com
* @copyright Copyright (c) 2019 silktide
* @copyright Copyright (c) 2019 Silktide Ltd
*/

namespace silktide\craftsilktide;
Expand Down
33 changes: 19 additions & 14 deletions src/CraftSilktideJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ public function execute($queue)
),
__METHOD__
);
$options = [
RequestOptions::BODY => http_build_query([
'apiKey' => $this->apiKey,
'urls' => [
$this->urls,
],
]),
];
$requestBody = http_build_query([
'apiKey' => $this->apiKey,
'urls' => [
$this->urls,
],
]);
$options = [RequestOptions::BODY => $requestBody];
$client = Craft::createGuzzleClient(
[
'headers' => [
Expand All @@ -83,14 +82,15 @@ public function execute($queue)
try {
$response = $client->request('post', self::SILKTIDE_API_URL,
$options);
$this->handleValidResponse($response);
$this->handleValidResponse($response, $requestBody);
} catch (RequestException $e) {
$message = Craft::t(
'craft-silktide',
'Failed to notify Silktide - exception type {exception} message: {message}',
'Failed to notify Silktide - exception type {exception} message: {message} with request body {request}',
[
'exception' => get_class($e),
'message' => $e->getMessage(),
'request' => $requestBody,
]
);
Craft::warning($message, __METHOD__);
Expand All @@ -102,33 +102,38 @@ public function execute($queue)

/**
* @param \Psr\Http\Message\ResponseInterface $response
* @param string $requestBody
*
* @throws \yii\base\ErrorException
*/
protected function handleValidResponse(ResponseInterface $response)
{
protected function handleValidResponse(
ResponseInterface $response,
string $requestBody
) {
$responseCode = (int)$response->getStatusCode();
$body = $response->getBody()->getContents();
if ($responseCode >= 200 && $responseCode <= 299) {
$decoded = json_decode($body, true);
if (is_array($decoded) && isset($decoded['status']) && $decoded['status'] === 'ok') {
$message = Craft::t(
'craft-silktide',
'Notified Silktide and received a {status} code back with {body}',
'Notified Silktide and received a {status} code back with {body} from {request}',
[
'status' => $responseCode,
'body' => $body,
'request' => $requestBody,
]
);
Craft::info($message, __METHOD__);
}
}
$message = Craft::t(
'craft-silktide',
'Failed to notify Silktide - HTTP request failed with status {status} and body {body}',
'Failed to notify Silktide - HTTP request failed with status {status} and body {body} from {request}',
[
'status' => $responseCode,
'body' => $body,
'request' => $requestBody,
]
);
Craft::warning($message, __METHOD__);
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Integrate Silktide with Craft
*
* @link https://www.silktide.com
* @copyright Copyright (c) 2019 silktide
* @copyright Copyright (c) 2019 Silktide Ltd.
*/

namespace silktide\craftsilktide\models;
Expand Down

0 comments on commit 31921e4

Please sign in to comment.