Skip to content

Commit 6a0cdb9

Browse files
authored
change deprecated Hub code (#9607)
1 parent d70f629 commit 6a0cdb9

File tree

1 file changed

+12
-11
lines changed
  • docs/platforms/javascript/common/troubleshooting

1 file changed

+12
-11
lines changed

docs/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,26 @@ end
198198
```javascript
199199
const SENTRY_HOST = "oXXXXXX.ingest.sentry.io"
200200
const SENTRY_PROJECT_IDS = ["123456"]
201-
201+
202202
export const postAction = async ({ request }) => {
203203
try {
204204
const envelope = await request.text();
205205
const piece = envelope.split("\n")[0];
206206
const header = JSON.parse(piece);
207207
const dsn = new URL(header["dsn"]);
208208
const project_id = dsn.pathname?.replace("/", "");
209-
209+
210210
if (dsn.hostname !== SENTRY_HOST) {
211211
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
212212
}
213-
213+
214214
if (!project_id || !SENTRY_PROJECT_IDS.includes(project_id)) {
215215
throw new Error(`Invalid sentry project id: ${project_id}`);
216216
}
217-
217+
218218
const upstream_sentry_url = `https://${SENTRY_HOST}/api/${project_id}/envelope/`;
219219
await fetch(upstream_sentry_url, { method: "POST", body: envelope });
220-
220+
221221
return json({}, { status: 200 });
222222
} catch (e) {
223223
console.error("error tunneling to sentry", e);
@@ -298,7 +298,7 @@ import {
298298
defaultStackParser,
299299
defaultIntegrations,
300300
makeFetchTransport,
301-
Hub,
301+
Scope,
302302
} from "@sentry/browser";
303303

304304
const client = new BrowserClient({
@@ -308,12 +308,13 @@ const client = new BrowserClient({
308308
integrations: defaultIntegrations,
309309
});
310310

311-
// You have to bind the client to a hub, otherwise integrations will not run!
312-
const hub = new Hub(client);
313-
// Or, if you already have a hub you want to re-use, you can also do:
314-
// hub.bindClient(client);
311+
const scope = new Scope();
312+
scope.setClient(client);
313+
314+
client.init() // initializing has to be done after setting the client on the scope
315315

316-
hub.captureException(new Error("example"));
316+
// You can capture exceptions manually for this client like this:
317+
scope.captureException(new Error("example"));
317318
```
318319
319320
You can now customize the hub to your liking, without affecting other hubs/clients.

0 commit comments

Comments
 (0)