Skip to content

Commit e76b9a8

Browse files
committed
#1 Easy way how to get occured errors +example
1 parent 3eeae94 commit e76b9a8

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

Examples/ErrorHandling.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/php -f
2+
<?php
3+
/**
4+
* php-flexibee - Example how to create Invoice
5+
*
6+
* @author Vítězslav Dvořák <[email protected]>
7+
* @copyright (G) 2020 Vitex Software
8+
*/
9+
10+
namespace Example\FlexiPeeHP;
11+
12+
use \FlexiPeeHP\FakturaVydana;
13+
14+
define('EASE_LOGGER', 'syslog|console');
15+
include_once './config.php';
16+
include_once '../vendor/autoload.php';
17+
18+
$invoicer = new FakturaVydana(['typDokl'=>'FAKTURA']); // "code:" is missing
19+
20+
if($invoicer->sync() === false){
21+
$invoicer->lastResponseCode; // (int) 400
22+
$invoicer->lastCurlError; // empty in this case
23+
$invoicer->lastCurlResponse; // {"winstrom":{"@version":"1.0","success":"false","stats":{"created":"0","updated":"0","deleted":"0","skipped":"0","failed":"1"},"results":[{"errors":[{"message":"Je očekáváno číselné ID, ale 'FAKTURA' není číslo","for":"typDokl","path":"faktura-vydana[temporary-id=null].typDokl","value":"FAKTURA","code":"PROP"}]}]}}
24+
$invoicer->getErrors(); // array(1) (
25+
// [0] => array(5) (
26+
// [message] => (string) Je očekáváno číselné ID, ale 'FAKTURA' není číslo
27+
// [for] => (string) typDokl
28+
// [path] => (string) faktura-vydana[temporary-id=null].typDokl
29+
// [value] => (string) FAKTURA
30+
// [code] => (string) PROP
31+
// )
32+
// )
33+
}
34+
35+
36+
37+
/* EASE_LOGGER: "console" print red/yellow lines:
38+
39+
php -f Examples/ErrorHandling.php
40+
03/21/20 03:29:47 `` ☠ Je očekáváno číselné ID, ale 'FAKTURA' není číslo
41+
03/21/20 03:29:47 `` ⚠ 400: https://vitexsoftware.flexibee.eu:5434/c/flexipeehp/faktura-vydana
42+
03/21/20 03:29:47 `` ☠ : Je očekáváno číselné ID, ale 'FAKTURA' není číslo for: typDokl value:FAKTURA code:PROP
43+
03/21/20 03:29:47 `` ⚙ {"for":"typDokl","path":"faktura-vydana[temporary-id=null].typDokl","value":"FAKTURA","code":"PROP"}
44+
03/21/20 03:29:47 `` ⚠ Error 400: https://vitexsoftware.flexibee.eu:5434/c/flexipeehp/faktura-vydana
45+
Done.
46+
*/
47+
48+
/* EASE_LOGGER "syslog" add this to /var/log/syslog
49+
50+
Mar 21 03:29:47 exiv FlexiPeeHPtest: ` ` 400: https://vitexsoftware.flexibee.eu:5434/c/flexipeehp/faktura-vydana
51+
Mar 21 03:29:47 exiv FlexiPeeHPtest:
52+
Mar 21 03:29:47 exiv FlexiPeeHPtest: ` ` Je očekáváno číselné ID, ale 'FAKTURA' není číslo
53+
Mar 21 03:29:47 exiv FlexiPeeHPtest:
54+
Mar 21 03:29:47 exiv FlexiPeeHPtest: ` ` @@ {"for":"typDokl","path":"faktura-vydana[temporary-id=null].typDokl","value":"FAKTURA","code":"PROP"}
55+
Mar 21 03:29:47 exiv FlexiPeeHPtest:
56+
Mar 21 03:29:47 exiv FlexiPeeHPtest: ` ` Error 400: https://vitexsoftware.flexibee.eu:5434/c/flexipeehp/faktura-vydana
57+
Mar 21 03:29:47 exiv FlexiPeeHPtest:
58+
Mar 21 03:29:47 exiv FlexiPeeHPtest: ` ` : Je očekáváno číselné ID, ale 'FAKTURA' není číslo for: typDokl value:FAKTURA code:PROP
59+
Mar 21 03:29:47 exiv FlexiPeeHPtest:
60+
61+
*/
62+

src/FlexiPeeHP/FlexiBeeRO.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class FlexiBeeRO extends \Ease\Sand
402402
/**
403403
* Class for read only interaction with FlexiBee.
404404
*
405-
* @param mixed $init default record id or initial data
405+
* @param mixed $init default record id or initial data. See processInit()
406406
* @param array $options Connection settings and other options override
407407
*/
408408
public function __construct($init = null, $options = [])
@@ -930,6 +930,7 @@ public function performRequest($urlSuffix = null, $method = 'GET',
930930
{
931931
$this->rowCount = null;
932932
$this->responseStats = [];
933+
$this->errors = [];
933934

934935
if (preg_match('/^http/', $urlSuffix)) {
935936
$url = $urlSuffix;
@@ -2868,6 +2869,15 @@ public function getLastOperationType()
28682869
return implode(',', array_keys(array_filter($this->responseStats)));
28692870
}
28702871

2872+
/**
2873+
* Last operation errors
2874+
*
2875+
* @return array FlexiBee error meassages
2876+
*/
2877+
public function getErrors() {
2878+
return $this->errors;
2879+
}
2880+
28712881
/**
28722882
* Reconnect After unserialization
28732883
*/

0 commit comments

Comments
 (0)