-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebServiceException.php
More file actions
117 lines (88 loc) · 4.2 KB
/
Copy pathWebServiceException.php
File metadata and controls
117 lines (88 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace PureMachine\Bundle\SDKBundle\Exception;
use PureMachine\Bundle\SDKBundle\Store\ExceptionStore;
use PureMachine\Bundle\SDKBundle\Store\WebService\DebugErrorResponse;
use PureMachine\Bundle\SDKBundle\Store\WebService\ErrorResponse;
use PureMachine\Bundle\SDKBundle\Store\WebService\Response;
class WebServiceException extends Exception
{
const DEFAULT_ERROR_CODE = 'WS_001';
const WS_001 = 'WS_001';
const WS_001_MESSAGE = 'webService error';
const WS_002 = 'WS_002';
const WS_002_MESSAGE = 'WebService lookup error';
const WS_003 = 'WS_003';
const WS_003_MESSAGE = 'WebService input data validation error';
const WS_004 = 'WS_004';
const WS_004_MESSAGE = 'WebService return data validation error';
const WS_005 = 'WS_005';
const WS_005_MESSAGE = 'Remote namespace configuration error';
const WS_006 = 'WS_006';
const WS_006_MESSAGE = 'webservice annotation error';
public static function raiseIfError($answer, $displayStack=false)
{
if ($answer->getStatus() != 'success') {
if ($answer instanceof ErrorResponse) {
$message = $answer->getAnswer()->getErrorCode() .": ". $answer->getAnswer()->getErrorMessage() ." \n";
if ($answer->getAnswer()->isStoreProperty('detailledMessage')) {
$message .= $answer->getAnswer()->getDetailledMessage();
}
$metadata = $answer->getAnswer()->getMetadata();
if (array_key_exists('merchantDetail', $metadata)) {
$message .= "\nmerchantDetail: " . $metadata['merchantDetail'] . "\n";
}
if ($displayStack && ($answer instanceof DebugErrorResponse)) {
$stack = $answer->getAnswer()->getStack();
foreach($stack as $line) print "$line\n";
}
} elseif($answer->isStoreProperty('metadata')) {
$message = $answer->getAnswer()->getMessage() . "\n";
$message .= "detailed: " . $answer->getAnswer()->getDetailedMessage() . "\n";
$metadata = $answer->getMetadata();
if (isset($metadata->internalMessage)) {
$message .= "internal: " . $metadata->internalMessage . "\n";
}
if (isset($metadata->merchantDetail)) {
$message .= "merchantDetail: " . $metadata->merchantDetail . "\n";
}
if ($answer->isStoreProperty('metadata')) {
if ($displayStack && $answer->isStoreProperty('metadata')) {
if (isset($metadata->line) && isset($metadata->file)) {
print "at " . $metadata->file . ":" . $metadata->line . "\n\n";
}
if (isset($metadata->stack) && is_array($metadata->stack)) {
foreach ($metadata->stack as $line) {
print $line . "\n";
}
}
}
}
} else {
$message = $answer->getAnswer()->getMessage();
}
/**
* Try to raise with the original exception class
*/
$exceptionStore = $answer->getAnswer();
if ($exceptionStore instanceof ExceptionStore) {
$class = $answer->getAnswer()->getExceptionClass();
if (class_exists($class)) {
$ex = null;
try {
$ex = new $class($message, $answer->getAnswer()->getErrorCode(), null);
if ($ex instanceof Exception) {
$ex->setStore($answer->getAnswer());
}
} catch (\Exception $e) {}
if ($ex instanceof \Exception) {
throw $ex;
}
}
}
$e = new WebServiceException($message);
$e->getStore()->setErrorMessage($answer->getAnswer()->getErrorMessage());
$e->getStore()->setErrorCode($answer->getAnswer()->getErrorCode());
throw $e;
}
}
}