-
Notifications
You must be signed in to change notification settings - Fork 42
Malformed UTF-8 characters
error when a QueryException is thrown
#14
Comments
Have had this issue myself, too. Can't think of a good enough reason to propose changing queryexception at the framework end. Custom exception handler? Seems like quite a jump for what isn't an especially common issue. |
Hi there, I'm having this issue too. What I did to have the original error message in the JSON response is this: In public function render($request, Throwable $exception)
{
if ($exception instanceof QueryException && $request->isJson()) {
$message = mb_convert_encoding($exception->getMessage(), 'ASCII');
throw new Exception($message);
}
return parent::render($request, $exception);
} This is working quite well as a workaround. |
Just another workaround: In protected function prepareJsonResponse($request, Throwable $e)
{
$exceptionArray = $this->convertExceptionToArray($e);
$exceptionArray['message'] = mb_convert_encoding($exceptionArray['message'], 'ASCII');
return new JsonResponse(
$exceptionArray,
$this->isHttpException($e) ? $e->getStatusCode() : 500,
$this->isHttpException($e) ? $e->getHeaders() : [],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
} |
A solution to this issue could be:
// src/LaravelEfficientUuidServiceProvider.php
public function boot()
{
$this->app->bind(ExceptionHandler::class, config('dyryndadb.error_handler'));
}
return [
...
'error_handler' => Dyrynda\Database\Exceptions\Handler::class,
]; @michaeldyrynda and others, would something like this be a welcomed PR or do you think this is too much aggressive. |
I'd much rather document this and provide one concrete way to address it. Providing an exception handler is tricky because users of the package possibly won't be able to just use it due to modification of their own app's handler. |
Worked for me too. But I needed to remove $request->isJson() on if. |
I've faced the same problem described here and here (but that package has been abandoned).
The problem occurs because the exception can't be formatted to normal JSON data since it contains binary. The problem can be solved by doing these changes in
illuminate\database\QueryException.php
:To:
But it's defiantly not a good idea. Any idea about solving it?
The text was updated successfully, but these errors were encountered: