graphql-python / graphql-python/graphql-core-legacy

Catching exceptions

Abierto
#202 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
372
Forks
175
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Using Graphene with graphql-core 2.0, I was able to write middleware that would catch errors:

```py
class ErrorHandlerMiddleware():
def resolve(self, next, root, info, **args):
try:
return next(root, info, **args)
except Exception as ex:

# log error with Sentry
info.context.sentry.captureException()

# Return a generic rejection
return GraphQLError("System error. Please try again later.")
```

It wasn't perfect. _Both_ the original exception and GraphQLError would wind up appearing as Sentry issues, but it'd at least get reported and send back a generic error to the user.

I've since bumped graphql-core to 2.1 to take advantage of the logging improvements, but I'm not clear on how the above could be achieved in 2.1? With the latest version, the original exception winds up in the `message` field of the response... potentially exposing sensitive info, like SQL errors, etc.

Could you please post an example in the README of how one might write middleware or use the new logging set-up to capture errors and replace the response with a generic message? I think that would be a really common use-case that many would find useful.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza revisando las indicaciones sobre el manejo de errores del README y el comportamiento de logging y middleware de graphql-core 2.1 descrito por el issue. Documenta un ejemplo compatible que capture las excepciones y devuelva una respuesta genérica sin exponer detalles sensibles; se considera terminado cuando el README explique la configuración y la respuesta esperada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api, documentation
Tipo de issue
Documentación
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.