Akylas / Akylas/nativescript-bugsnag

Unable to automatically handle promise rejections

未关闭
#2 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
4
派生
3
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。