Akylas / Akylas/nativescript-bugsnag

Unable to automatically handle promise rejections

Open
#2 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4
Forks
3
PR merge metrics
No merged PRs in 30d

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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.