Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.

Commit 0d68ae2

Browse files
Improve error handling (#7)
* Improve documentation - add navigation link * Improve error handling * Version bump to 1.0.1 * Optimize the code for the bug fix * Improve code
1 parent fe9d6ad commit 0d68ae2

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "SumUp eCom SDK for PHP",
44
"type": "library",
55
"license": "proprietary",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"keywords": ["sumup", "sdk", "payment processing", "ecommerce", "payment", "checkout"],
88
"homepage": "https://developer.sumup.com",
99
"authors": [

src/SumUp/HttpClients/Response.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,36 @@ protected function parseResponseForErrors()
9595
throw new SumUpValidationException($invalidFields, $this->httpResponseCode);
9696
}
9797
if ($this->httpResponseCode >= 500) {
98-
$message = (!is_null($this->body) && !is_null($this->body->message)) ? $this->body->message : $this->body;
98+
$message = $this->parseErrorMessage('Server error');
9999
throw new SumUpServerException($message, $this->httpResponseCode);
100100
}
101101
if ($this->httpResponseCode >= 400) {
102-
$message = (!is_null($this->body) && !is_null($this->body->message)) ? $this->body->message : $this->body;
102+
$message = $this->parseErrorMessage('Client error');
103103
throw new SumUpResponseException($message, $this->httpResponseCode);
104104
}
105105
}
106+
107+
/**
108+
* Return error message.
109+
*
110+
* @param string $defaultMessage
111+
*
112+
* @return string
113+
*/
114+
protected function parseErrorMessage($defaultMessage = '')
115+
{
116+
if (is_null($this->body)) {
117+
return $defaultMessage;
118+
}
119+
120+
if (isset($this->body->message)) {
121+
return $this->body->message;
122+
}
123+
124+
if (isset($this->body->error_message)) {
125+
return $this->body->error_message;
126+
}
127+
128+
return $defaultMessage;
129+
}
106130
}

0 commit comments

Comments
 (0)