mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-03 09:35:57 +02:00
feat: improve error handling ux (#3298)
* feat: improve error handling ux * feat: add error messages for failed xml parsing
This commit is contained in:
parent
9e9a697b8b
commit
4c3ebb312d
4 changed files with 70 additions and 27 deletions
|
@ -178,29 +178,28 @@ function getContents(
|
|||
$response['content'] = $cache->loadData();
|
||||
break;
|
||||
default:
|
||||
if (Debug::isEnabled()) {
|
||||
// Include a part of the response body in the exception message
|
||||
throw new HttpException(
|
||||
sprintf(
|
||||
'%s resulted in `%s %s: %s`',
|
||||
$url,
|
||||
$result['code'],
|
||||
Response::STATUS_CODES[$result['code']] ?? '',
|
||||
mb_substr($result['body'], 0, 500),
|
||||
),
|
||||
$result['code']
|
||||
);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
sprintf(
|
||||
'%s resulted in `%s %s`',
|
||||
$url,
|
||||
$result['code'],
|
||||
Response::STATUS_CODES[$result['code']] ?? '',
|
||||
),
|
||||
$result['code']
|
||||
);
|
||||
$exceptionMessage = sprintf(
|
||||
'%s resulted in %s %s %s',
|
||||
$url,
|
||||
$result['code'],
|
||||
Response::STATUS_CODES[$result['code']] ?? '',
|
||||
// If debug, include a part of the response body in the exception message
|
||||
Debug::isEnabled() ? mb_substr($result['body'], 0, 500) : '',
|
||||
);
|
||||
|
||||
// The following code must be extracted if it grows too much
|
||||
$cloudflareTitles = [
|
||||
'<title>Just a moment...',
|
||||
'<title>Please Wait...',
|
||||
'<title>Attention Required!'
|
||||
];
|
||||
foreach ($cloudflareTitles as $cloudflareTitle) {
|
||||
if (str_contains($result['body'], $cloudflareTitle)) {
|
||||
throw new CloudFlareException($exceptionMessage, $result['code']);
|
||||
}
|
||||
}
|
||||
|
||||
throw new HttpException($exceptionMessage, $result['code']);
|
||||
}
|
||||
if ($returnFull === true) {
|
||||
return $response;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue