Skip to content

Commit 802b5f4

Browse files
committed
Improve logging
1 parent 76c4bdc commit 802b5f4

File tree

5 files changed

+71
-28
lines changed

5 files changed

+71
-28
lines changed

plugin/aplazame.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ class WC_Aplazame {
2222
const VERSION = '0.4.5';
2323
const METHOD_ID = 'aplazame';
2424
const METHOD_TITLE = 'Aplazame';
25+
26+
/**
27+
* @param string $msg
28+
*/
29+
public static function log( $msg ) {
30+
$log = new WC_Logger();
31+
$log->add( self::METHOD_ID, $msg );
32+
}
33+
2534
/**
2635
* @var array
2736
*/
@@ -139,16 +148,6 @@ public function plugin_action_links( $links ) {
139148
return array_merge( $plugin_links, $links );
140149
}
141150

142-
/**
143-
* @param string $msg
144-
*/
145-
public function log( $msg ) {
146-
if ( $this->sandbox ) {
147-
$log = new WC_Logger();
148-
$log->add( self::METHOD_ID, $msg );
149-
}
150-
}
151-
152151
/**
153152
* @return Aplazame_Client
154153
*/
@@ -241,7 +240,9 @@ public function confirm() {
241240
$e->getMessage()
242241
) );
243242

244-
throw $e;
243+
status_header( 500 );
244+
245+
return null;
245246
}
246247

247248
$order->update_status( 'processing', sprintf( __( 'Confirmed by %s.', 'aplazame' ), $this->apiBaseUri ) );

plugin/classes/sdk/Client.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct( $apiBaseUri, $sandbox, $private_api_key ) {
3636
* @throws Aplazame_Sdk_Api_ApiServerException if request is invalid.
3737
*/
3838
protected function order_request( $order_id, $method, $path, $data = null ) {
39-
return $this->apiClient->request( $method, '/orders/' . $order_id . $path, $data );
39+
return $this->request( $method, '/orders/' . $order_id . $path, $data );
4040
}
4141

4242
/**
@@ -97,8 +97,43 @@ public function cancel( $order_id ) {
9797
* @throws Aplazame_Sdk_Api_ApiServerException if request is invalid.
9898
*/
9999
public function fetch( $order_id ) {
100-
$orders = $this->apiClient->request( 'GET', '/orders?mid=' . $order_id );
100+
$orders = $this->request( 'GET', '/orders?mid=' . $order_id );
101101

102102
return $orders['results'][0];
103103
}
104+
/**
105+
* @param string $method The HTTP method of the request.
106+
* @param string $path The path of the request.
107+
* @param array|null $data The data of the request.
108+
*
109+
* @return array The data of the response.
110+
*
111+
* @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
112+
* @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
113+
* @throws Aplazame_Sdk_Api_ApiClientException if an I/O error occurs.
114+
* @throws Aplazame_Sdk_Api_ApiServerException if request is invalid.
115+
*/
116+
public function request( $method, $path, array $data = null ) {
117+
try {
118+
return $this->apiClient->request( $method, $path, $data );
119+
} catch (Aplazame_Sdk_Api_ApiClientException $e) {
120+
$details = json_encode( $e->getError() );
121+
122+
WC_Aplazame::log( "Error: {$path}; {$e->getStatusCode()}; {$details}" );
123+
124+
throw $e;
125+
} catch (Aplazame_Sdk_Api_ApiServerException $e) {
126+
$details = json_encode( $e->getError() );
127+
128+
WC_Aplazame::log( "Error: {$path}; {$e->getStatusCode()}; {$details}" );
129+
130+
throw $e;
131+
} catch (Exception $e) {
132+
$exceptionClass = get_class( $e );
133+
134+
WC_Aplazame::log( "Error: {$path} {$exceptionClass} {$e->getMessage()}" );
135+
136+
throw $e;
137+
}
138+
}
104139
}

plugin/l10n/es/aplazame-es_ES.mo

52 Bytes
Binary file not shown.

plugin/l10n/es/default.po

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
msgid ""
22
msgstr ""
33
"Report-Msgid-Bugs-To: https://github.com/aplazame/woocommerce\n"
4-
"POT-Creation-Date: 2017-01-29 12:19+0000\n"
4+
"POT-Creation-Date: 2017-02-22 12:26+0000\n"
55
"Language: es_ES\n"
66
"MIME-Version: 1.0\n"
77
"Content-Type: text/plain; charset=UTF-8\n"
88
"Content-Transfer-Encoding: 8bit\n"
99

10-
#: aplazame.php:119
10+
#: aplazame.php:128
1111
msgid "Aplazame Campaigns"
1212
msgstr "Campañas Aplazame"
1313

14-
#: aplazame.php:137
14+
#: aplazame.php:146
1515
msgid "Settings"
1616
msgstr "Ajustes"
1717

18-
#: aplazame.php:227
18+
#: aplazame.php:237
1919
#, php-format
2020
msgid "%s ERROR: Order #%s cannot be confirmed. Reason: %s"
2121
msgstr ""
2222

23-
#: aplazame.php:293
23+
#: aplazame.php:248
24+
#, php-format
25+
msgid "Confirmed by %s."
26+
msgstr "Confirmado por %s."
27+
28+
#: aplazame.php:316
2429
#, php-format
2530
msgid "%s ERROR: Order #%s cannot be cancelled. Reason: %s"
2631
msgstr ""
2732

28-
#: aplazame.php:303
33+
#: aplazame.php:326
2934
#, php-format
3035
msgid "Order #%s has been successful cancelled by %s."
3136
msgstr "El pedido #%s ha sido cancelado correctamente por %s."
@@ -141,8 +146,5 @@ msgstr "La campaña aplica a todo el catálogo de productos."
141146
#~ msgid "%s ERROR: Order #%s cannot be confirmed."
142147
#~ msgstr "ERROR en %s: El pedido #%s no se ha podido confirmar."
143148

144-
#~ msgid "Confirmed by %s."
145-
#~ msgstr "Confirmado por %s."
146-
147149
#~ msgid "%s ERROR: Order #%s cannot be cancelled."
148150
#~ msgstr "ERROR en %s: El pedido #%s no se ha podido cancelar."

plugin/l10n/es/default.pot

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: Aplazame v0.4.5\n"
1010
"Report-Msgid-Bugs-To: https://github.com/aplazame/woocommerce\n"
11-
"POT-Creation-Date: 2017-01-29 12:19+0000\n"
11+
"POT-Creation-Date: 2017-02-22 12:26+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: https://github.com/aplazame/woocommerce\n"
@@ -17,25 +17,30 @@ msgstr ""
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: aplazame.php:119
20+
#: aplazame.php:128
2121
msgid "Aplazame Campaigns"
2222
msgstr ""
2323

24-
#: aplazame.php:137
24+
#: aplazame.php:146
2525
msgid "Settings"
2626
msgstr ""
2727

28-
#: aplazame.php:227
28+
#: aplazame.php:237
2929
#, php-format
3030
msgid "%s ERROR: Order #%s cannot be confirmed. Reason: %s"
3131
msgstr ""
3232

33-
#: aplazame.php:293
33+
#: aplazame.php:248
34+
#, php-format
35+
msgid "Confirmed by %s."
36+
msgstr ""
37+
38+
#: aplazame.php:316
3439
#, php-format
3540
msgid "%s ERROR: Order #%s cannot be cancelled. Reason: %s"
3641
msgstr ""
3742

38-
#: aplazame.php:303
43+
#: aplazame.php:326
3944
#, php-format
4045
msgid "Order #%s has been successful cancelled by %s."
4146
msgstr ""

0 commit comments

Comments
 (0)