mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-26 08:51:13 -06:00
Fixed ContentBased error handler not using the default content if accepted contents are not valid
This commit is contained in:
parent
ab6aa99a6d
commit
c569cef239
@ -47,6 +47,7 @@ class ContentBasedErrorHandler extends AbstractPluginManager implements ErrorHan
|
||||
*/
|
||||
protected function resolveErrorHandlerFromAcceptHeader(Request $request)
|
||||
{
|
||||
// Try to find an error handler for one of the accepted content types
|
||||
$accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : self::DEFAULT_CONTENT;
|
||||
$accepts = explode(',', $accepts);
|
||||
foreach ($accepts as $accept) {
|
||||
@ -57,8 +58,17 @@ class ContentBasedErrorHandler extends AbstractPluginManager implements ErrorHan
|
||||
return $this->get($accept);
|
||||
}
|
||||
|
||||
// If it wasn't possible to find an error handler for accepted content type, use default one if registered
|
||||
if ($this->has(self::DEFAULT_CONTENT)) {
|
||||
return $this->get(self::DEFAULT_CONTENT);
|
||||
}
|
||||
|
||||
// It wasn't possible to find an error handler
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'It wasn\'t possible to find an error handler for '
|
||||
'It wasn\'t possible to find an error handler for ["%s"] content types. '
|
||||
. 'Make sure you have registered at least the default "%s" content type',
|
||||
implode('", "', $accepts),
|
||||
self::DEFAULT_CONTENT
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user