mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-10 17:08:47 +00:00
feat: in debug mode, include part of http response in exception message (#3090)
This commit is contained in:
parent
85b87b9597
commit
1f576312ea
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
// todo: move this somewhere useful, possibly into a function
|
||||
const RSSBRIDGE_HTTP_STATUS_CODES = [
|
||||
final class Response
|
||||
{
|
||||
public const STATUS_CODES = [
|
||||
'100' => 'Continue',
|
||||
'101' => 'Switching Protocols',
|
||||
'200' => 'OK',
|
||||
@ -43,6 +44,7 @@ const RSSBRIDGE_HTTP_STATUS_CODES = [
|
||||
'504' => 'Gateway Timeout',
|
||||
'505' => 'HTTP Version Not Supported'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data from an http url
|
||||
@ -135,16 +137,30 @@ 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'],
|
||||
RSSBRIDGE_HTTP_STATUS_CODES[$result['code']] ?? ''
|
||||
Response::STATUS_CODES[$result['code']] ?? '',
|
||||
),
|
||||
$result['code']
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($returnFull === true) {
|
||||
return $response;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user