Skip to content

Commit 0316f61

Browse files
committed
catch the error in our base api functions
1 parent 3dc6a02 commit 0316f61

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

utils/api/base.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import axios from 'axios'
2+
import * as Sentry from '@sentry/nextjs'
23

34
const baseURL = `https://${process.env.NEXT_PUBLIC_PROVIDER_NAME}.scientist.com/api/${process.env.NEXT_PUBLIC_SCIENTIST_API_VERSION}`
45
// Use the user's own access token if they are signed in. If not, fall back to the access token provided through the provider credentials
56
const defaultHeaders = (token) => ({ Authorization: `Bearer ${token || process.env.NEXT_PUBLIC_TOKEN}` })
67
const api = axios.create({ baseURL })
78

89
export const fetcher = (url, token) => {
9-
try {
10-
return api.get(url, { headers: defaultHeaders(token) })
11-
.then(res => res.data)
12-
} catch (error) {
13-
// TODO(alishaevn): handle the error when sentry is set up
14-
console.error(`The following error occurred when trying to retrieve data:`, error)
15-
}
10+
return api.get(url, { headers: defaultHeaders(token) })
11+
.then(res => res.data)
12+
.catch(error => {
13+
Sentry.captureException(error)
14+
})
1615
}
1716

1817
export const posting = async (url, data, token) => {
@@ -24,9 +23,12 @@ export const posting = async (url, data, token) => {
2423
error: false,
2524
}
2625
} catch (error) {
27-
// TODO(alishaevn): handle the error when sentry is set up
28-
console.error(`The following error occurred when trying to post new data:`, error)
29-
return { success: false, error, requestID: undefined }
26+
Sentry.captureException(error)
27+
28+
return {
29+
data: undefined,
30+
error,
31+
}
3032
}
3133
}
3234

@@ -39,8 +41,8 @@ export const updating = async (url, data, token) => {
3941
error: false,
4042
}
4143
} catch (error) {
42-
// TODO(alishaevn): handle the error when sentry is set up
43-
console.error(`The following error occurred when trying to update data:`, error)
44+
Sentry.captureException(error)
45+
4446
return {
4547
data: undefined,
4648
error,

0 commit comments

Comments
 (0)