1
1
import axios from 'axios'
2
+ import * as Sentry from '@sentry/nextjs'
2
3
3
4
const baseURL = `https://${ process . env . NEXT_PUBLIC_PROVIDER_NAME } .scientist.com/api/${ process . env . NEXT_PUBLIC_SCIENTIST_API_VERSION } `
4
5
// 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
5
6
const defaultHeaders = ( token ) => ( { Authorization : `Bearer ${ token || process . env . NEXT_PUBLIC_TOKEN } ` } )
6
7
const api = axios . create ( { baseURL } )
7
8
8
9
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
+ } )
16
15
}
17
16
18
17
export const posting = async ( url , data , token ) => {
@@ -24,9 +23,12 @@ export const posting = async (url, data, token) => {
24
23
error : false ,
25
24
}
26
25
} 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
+ }
30
32
}
31
33
}
32
34
@@ -39,8 +41,8 @@ export const updating = async (url, data, token) => {
39
41
error : false ,
40
42
}
41
43
} 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
+
44
46
return {
45
47
data : undefined ,
46
48
error,
0 commit comments