Skip to content

Commit a465074

Browse files
committed
improve debug message for #520
1 parent e6115e3 commit a465074

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/Tqdev/PhpCrudApi/Api.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,18 @@ public function handle(Request $request): Response
123123
} catch (\Throwable $e) {
124124
if ($e instanceof \PDOException) {
125125
if (strpos(strtolower($e->getMessage()), 'duplicate') !== false) {
126-
return $this->responder->error(ErrorCode::DUPLICATE_KEY_EXCEPTION, '');
127-
}
128-
if (strpos(strtolower($e->getMessage()), 'default value') !== false) {
129-
return $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
130-
}
131-
if (strpos(strtolower($e->getMessage()), 'allow nulls') !== false) {
132-
return $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
133-
}
134-
if (strpos(strtolower($e->getMessage()), 'constraint') !== false) {
135-
return $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
126+
$response = $this->responder->error(ErrorCode::DUPLICATE_KEY_EXCEPTION, '');
127+
} elseif (strpos(strtolower($e->getMessage()), 'default value') !== false) {
128+
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
129+
} elseif (strpos(strtolower($e->getMessage()), 'allow nulls') !== false) {
130+
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
131+
} elseif (strpos(strtolower($e->getMessage()), 'constraint') !== false) {
132+
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
136133
}
137134
}
138-
$response = $this->responder->error(ErrorCode::ERROR_NOT_FOUND, $e->getMessage());
135+
if (!$response) {
136+
$response = $this->responder->error(ErrorCode::ERROR_NOT_FOUND, $e->getMessage());
137+
}
139138
if ($this->debug) {
140139
$response->addHeader('X-Exception-Message', $e->getMessage());
141140
$response->addHeader('X-Exception-File', $e->getFile() . ':' . $e->getLine());

0 commit comments

Comments
 (0)