Skip to content

Commit 6e367ad

Browse files
authored
Merge pull request #2662 from bugsnag/test/react-native-http-errors
Mark HTTP errors as handled instead of unhandled
1 parent 45090d9 commit 6e367ad

13 files changed

Lines changed: 108 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
Update bugsnag-android to [v6.22.0](https//github.com/bugsnag/bugsnag-android/releases/tag/v6.22.0) [#2656](https://github.com/bugsnag/bugsnag-js/pull/2656)
88

9+
### Fixed
10+
11+
(plugin-network-instrumentation) Report HTTP Errors as handled [#2662](https://github.com/bugsnag/bugsnag-js/pull/2662)
12+
913
## [8.8.1] - 2026-01-26
1014

1115
### Fixed

packages/plugin-network-instrumentation/network-instrumentation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module.exports = (config = {}, global = window) => {
136136

137137
const handledState = {
138138
severity: 'error',
139-
unhandled: true,
139+
unhandled: false,
140140
severityReason: { type: 'httpError' }
141141
}
142142

packages/plugin-network-instrumentation/test/network-instrumentation-xhr.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('plugin-network-instrumentation', () => {
135135
expect(event.exceptions[0].errorMessage).toBe('404: https://api.example.com/users/123')
136136
expect(event.context).toBe('POST api.example.com')
137137
expect(event.severity).toBe('error')
138-
expect(event.unhandled).toBe(true)
138+
expect(event.unhandled).toBe(false)
139139
expect(event.severityReason.type).toBe('httpError')
140140

141141
// Verify request metadata

packages/plugin-network-instrumentation/test/network-instrumentation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('plugin-network-instrumentation', () => {
8787
expect(event.exceptions[0].errorMessage).toBe('404: https://example.com/api/users')
8888
expect(event.context).toBe('GET example.com')
8989
expect(event.severity).toBe('error')
90-
expect(event.unhandled).toBe(true)
90+
expect(event.unhandled).toBe(false)
9191
expect(event.severityReason.type).toBe('httpError')
9292
expect(event.request.url).toBe('https://example.com/api/users')
9393
expect(event.request.httpMethod).toBe('GET')

scripts/generate-react-native-fixture.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const replacementFilesDir = resolve(ROOT_DIR, 'test/react-native/features/fixtur
4040

4141
const INTERNAL_DEPENDENCIES = [
4242
'@bugsnag/react-native',
43-
'@bugsnag/request-tracker'
43+
'@bugsnag/request-tracker',
44+
'@bugsnag/plugin-network-instrumentation'
4445
]
4546

4647
// make sure we install a compatible versions of peer dependencies

test/react-native/features/breadcrumbs.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ Scenario: Manual breadcrumbs (Native)
4747
| ios | NSException |
4848
And the exception "message" equals "BreadcrumbsNativeManualScenario"
4949
And the event contains a breadcrumb matching the JSON fixture in "features/fixtures/expected_breadcrumbs/NativeManualScenario.json"
50+
51+
Scenario: Network breadcrumbs (JS)
52+
When I run "NetworkBreadcrumbsJsScenario"
53+
Then I wait to receive an error
54+
And the exception "errorClass" equals "Error"
55+
And the exception "message" equals "NetworkBreadcrumbsJsScenario"
56+
And the event contains a breadcrumb matching the JSON fixture in "features/fixtures/expected_breadcrumbs/NetworkJsScenario.json"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "request",
3+
"name": "XMLHttpRequest succeeded",
4+
"timestamp": "^\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:[\\d\\.]+Z?$",
5+
"metaData": {
6+
"status": "NUMBER",
7+
"method": "GET",
8+
"url": "^http:\/\/[0-9.:]*\/reflect$",
9+
"duration": "NUMBER"
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"message": "^401: .*\/reflect\/[?]status=401$",
4+
"errorClass": "HTTPError",
5+
"type": "reactnativejs",
6+
"stacktrace": "IGNORE"
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"message": "^500: .*\/reflect\/[?]status=500$",
4+
"errorClass": "HTTPError",
5+
"type": "reactnativejs",
6+
"stacktrace": "IGNORE"
7+
}
8+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Scenario from './Scenario'
2+
import Bugsnag from '@bugsnag/react-native'
3+
4+
export class NetworkBreadcrumbsJsScenario extends Scenario {
5+
constructor (nativeConfig, jsConfig, scenarioData) {
6+
super()
7+
this.reflectEndpoint = nativeConfig.endpoints.notify.replace('/notify', '/reflect')
8+
}
9+
10+
run () {
11+
fetch(this.reflectEndpoint).then(() => {
12+
Bugsnag.notify(new Error('NetworkBreadcrumbsJsScenario'))
13+
})
14+
}
15+
}

0 commit comments

Comments
 (0)