Akylas / Akylas/nativescript-bugsnag

Unable to automatically handle promise rejections

Offen
#2 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
4
Forks
3
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### 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!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.