diff --git a/module/Common/src/Expressive/ContentBasedErrorHandler.php b/module/Common/src/Expressive/ContentBasedErrorHandler.php index 60e1dfdb..7dbe2509 100644 --- a/module/Common/src/Expressive/ContentBasedErrorHandler.php +++ b/module/Common/src/Expressive/ContentBasedErrorHandler.php @@ -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 )); } }