graphql-python / graphql-python/graphql-core-legacy
Catching exceptions
- Langage dominant
- Python
- Étoiles
- 372
- Forks
- 175
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par examiner les indications du README concernant la gestion des erreurs ainsi que le comportement de logging et de middleware de graphql-core 2.1 décrit par l’issue. Documentez un exemple pris en charge qui capture les exceptions et renvoie une réponse générique sans exposer de détails sensibles ; le travail est terminé lorsque le README explique la configuration et la réponse attendue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api, documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100