Akylas / Akylas/nativescript-bugsnag

Unable to automatically handle promise rejections

Ouverte
#2 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
4
Forks
3
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

### Which platform(s) does your issue occur on?
- iOS 11.4 emulator

### Please, provide the following version numbers that your issue occurs with:
- CLI: 5.3.4
- Cross-platform modules: 5.3.2
- Runtime(s): 5.3.1
- Plugin(s): nativescript-bugsnag 1.0.7

### Please, tell us how to recreate the issue in as much detail as possible.
I'm using Axios to make HTTP requests across my application, and would like to avoid adding `.catch` blocks to each one, so I'm trying to configure Bugsnag to automatically catch these promise rejections.

The README states:
> By default, unhandled promise rejections are reported in production.

but I haven't been able to get this to work.

Looking at the code, it seems `handleUncaughtErrors` is meant to register these global handlers, but this method isn't called as part of the Bugsnag initialization.

I added `bugsnag.handleUncaughtErrors()` to my consumer code after Bugsnag has been initialized (see below), but unhandled promise rejections are still not caught automatically. I have to use `bugsnag.notify()` each time I need to report an error. I would really appreciate your help figuring this out, so I don't have to litter my codebase with `bugsnag.notify()` calls :smile:

### Is there any code involved?
```
// Bugsnag initialization
const bugsnag = new Client()
bugsnag
.init(my-api-key)
.then(res => {
bugsnag.enableConsoleBreadcrumbs()
bugsnag.handleUncaughtErrors()
console.log('bugsnag did init', !!res)
})
.catch(err => {
console.log('bugsnag init failed', err)
})

[...]

// This unhandled Promise rejection (resulting in a 404) is not caught by Bugsnag
axios
.get('/api/invalid/url')
.then(response => {
console.log(response.data)
})
```

Instead, this is the only way I can get it to work:
```
axios
.get('/api/invalid/url')
.then(response => {
console.log(response.data)
})
.catch(error => {
bugsnag.notify(error)
})
```

P.S. Thank you for your work on this library!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.