-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors get swallowed up #537
Comments
We can certainly add an extension point, e.g. |
I've been trying to wrap my head around this and have found that I was partially chasing a red herring - in dev mode triggered errors are handled by In live mode that doesn't happen, but one drawback is that the client receives an HTML formatted friendly error message response. It might be nice if the default behaviour was to allow normal Silverstripe error handling/logging, but use a formatter appropriate for a GraphQL response. In practice though I don't know if that would make a difference for the client, since it would get a 500 response code? In either mode I found that if I throw an Anyway... as per the example code above, it is possible to get a hold of the original exception thrown in a resolver within The change below seems to accomplish what I want and allow exceptions to be logged. I could achieve that if we add an extension point, or perhaps it would be worth adding to the module? I'm not well versed on best practices around throwing exceptions in PHP and whether the below would suit all users, but I do feel that there's a hole in GraphQL error logging capabilities currently. public function query(GraphQLSchema $schema, $query, ?array $vars = []): array
{
$executionResult = $this->queryAndReturnResult($schema, $query, $vars);
// START -- Log exceptions
$errors = $executionResult->errors ?? [];
foreach ($errors as $error) {
$e = $error->getPrevious();
// Error caused by the app-resolver
if ($e) {
$level = 'error';
if ($e instanceof \ErrorException) {
$severity = $e->getSeverity();
if (in_array($severity, [E_WARNING, E_USER_WARNING])) {
$level = 'warning';
} else if (in_array($severity, [E_NOTICE, E_USER_NOTICE])) {
$level = 'notice';
}
}
Injector::inst()->get(LoggerInterface::class)->$level($e->getMessage(), [
'file' => $e->getFile(),
'line' => $e->getLine(),
]);
}
}
// END -- Log exceptions
// Already in array form
if (is_array($executionResult)) {
return $executionResult;
}
return $this->serialiseResult($executionResult);
} |
Had a quick look at this today because I think we’re also missing the use case of partial data/partial error. I.e. in the response, both Currently, if an error is encountered during dev it replaces the |
Hi there,
I was trying to add Sentry error tracking to a project but found that errors thrown during a GraphQL request get swallowed up. It seems that graphql-php catches the error first, but even if I was to re-throw it somehow, this module would catch it as well.
Sorry if I'm missing something obvious here but I'm wondering how to log errors properly.
I found that if I hacked
QueryHandler::query()
I could manually report an error, so I'm wondering if some logging code should be added here, or perhaps an extension point?The text was updated successfully, but these errors were encountered: