Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
813c4dd7
Commit
813c4dd7
authored
Feb 28, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add meta data to sentry errors
parent
c9ea7805
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
16 deletions
+38
-16
resources.ts
lib/api/resources.ts
+6
-1
useApiFetch.tsx
lib/api/useApiFetch.tsx
+15
-9
useFetch.tsx
lib/hooks/useFetch.tsx
+7
-3
useGetCsrfToken.tsx
lib/hooks/useGetCsrfToken.tsx
+8
-1
useRedirectForInvalidAuthToken.tsx
lib/hooks/useRedirectForInvalidAuthToken.tsx
+1
-1
AddressQrCode.tsx
ui/address/details/AddressQrCode.tsx
+1
-1
No files found.
lib/api/resources.ts
View file @
813c4dd7
...
...
@@ -41,7 +41,7 @@ import type ArrayElement from 'types/utils/ArrayElement';
import
appConfig
from
'
configs/app/config
'
;
export
interface
ApiResource
{
path
:
string
;
path
:
ResourcePath
;
endpoint
?:
string
;
basePath
?:
string
;
pathParams
?:
Array
<
string
>
;
...
...
@@ -364,6 +364,11 @@ export const RESOURCES = {
export
type
ResourceName
=
keyof
typeof
RESOURCES
;
type
ResourcePathMap
=
{
[
K
in
ResourceName
]:
typeof
RESOURCES
[
K
][
'
path
'
]
}
export
type
ResourcePath
=
ResourcePathMap
[
keyof
ResourcePathMap
]
export
type
ResourceFiltersKey
<
R
extends
ResourceName
>
=
typeof
RESOURCES
[
R
]
extends
{
filterFields
:
Array
<
unknown
>
}
?
ArrayElement
<
typeof
RESOURCES
[
R
][
'
filterFields
'
]
>
:
never
;
...
...
lib/api/useApiFetch.tsx
View file @
813c4dd7
...
...
@@ -23,14 +23,20 @@ export default function useApiFetch() {
) =
>
{
const
resource
:
ApiResource
=
RESOURCES
[
resourceName
];
const
url
=
buildUrl
(
resourceName
,
pathParams
,
queryParams
);
return
fetch
<
SuccessType
,
ErrorType
>
(
url
,
{
credentials
:
'
include
'
,
...(
resource
.
endpoint
&&
appConfig
.
host
===
'
localhost
'
?
{
headers
:
{
'
x-endpoint
'
:
resource
.
endpoint
,
},
}
:
{}),
...
fetchParams
,
});
return
fetch
<
SuccessType
,
ErrorType
>
(
url
,
{
credentials
:
'
include
'
,
...(
resource
.
endpoint
&&
appConfig
.
host
===
'
localhost
'
?
{
headers
:
{
'
x-endpoint
'
:
resource
.
endpoint
,
},
}
:
{}),
...
fetchParams
,
},
{
resource
:
resource
.
path
,
},
);
}
, [ fetch ]);
}
lib/hooks/useFetch.tsx
View file @
813c4dd7
...
...
@@ -4,7 +4,7 @@ import React from 'react';
import
type
{
CsrfData
}
from
'
types/client/account
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
type
{
ResourceError
,
ResourcePath
}
from
'
lib/api/resources
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
export
interface
Params
{
...
...
@@ -15,11 +15,15 @@ export interface Params {
credentials
?:
RequestCredentials
;
}
interface
Meta
{
resource
?:
ResourcePath
;
}
export
default
function
useFetch
()
{
const
queryClient
=
useQueryClient
();
const
{
token
}
=
queryClient
.
getQueryData
<
CsrfData
>
(
getResourceKey
(
'
csrf
'
))
||
{};
return
React
.
useCallback
(<
Success
,
Error
>
(path: string, params?: Params): Promise
<
Success
|
ResourceError
<
Error
>
>
=
>
{
return
React
.
useCallback
(<
Success
,
Error
>
(path: string, params?: Params
, meta?: Meta
): Promise
<
Success
|
ResourceError
<
Error
>
>
=
>
{
const
_body
=
params
?.
body
;
const
isFormData
=
_body
instanceof
FormData
;
const
isBodyAllowed
=
params
?.
method
&&
!
[
'
GET
'
,
'
HEAD
'
].
includes
(
params
.
method
);
...
...
@@ -51,7 +55,7 @@ export default function useFetch() {
status
:
response
.
status
,
statusText
:
response
.
statusText
,
};
Sentry
.
captureException
(
new
Error
(
'
Client fetch failed
'
),
{
extra
:
error
,
tags
:
{
source
:
'
fetch
'
}
});
Sentry
.
captureException
(
new
Error
(
'
Client fetch failed
'
),
{
extra
:
{
...
error
,
...
meta
},
tags
:
{
source
:
'
api_
fetch
'
}
});
return
response
.
json
().
then
(
(
jsonError
)
=>
Promise
.
reject
({
...
...
lib/hooks/useGetCsrfToken.tsx
View file @
813c4dd7
import
*
as
Sentry
from
'
@sentry/react
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
buildUrl
from
'
lib/api/buildUrl
'
;
...
...
@@ -14,7 +15,13 @@ export default function useGetCsrfToken() {
const
url
=
buildUrl
(
'
csrf
'
);
const
apiResponse
=
await
fetch
(
url
,
{
credentials
:
'
include
'
});
const
csrfFromHeader
=
apiResponse
.
headers
.
get
(
'
x-bs-account-csrf
'
);
return
csrfFromHeader
?
{
token
:
csrfFromHeader
}
:
undefined
;
if
(
!
csrfFromHeader
)
{
Sentry
.
captureException
(
new
Error
(
'
Unable to get csrf token
'
),
{
tags
:
{
source
:
'
csrf_token
'
}
});
return
;
}
return
{
token
:
csrfFromHeader
};
}
return
nodeApiFetch
(
'
/node-api/csrf
'
);
...
...
lib/hooks/useRedirectForInvalidAuthToken.tsx
View file @
813c4dd7
...
...
@@ -19,7 +19,7 @@ export default function useRedirectForInvalidAuthToken() {
const
apiToken
=
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
);
if
(
apiToken
)
{
Sentry
.
captureException
(
new
Error
(
'
Invalid api token
'
),
{
tags
:
{
source
:
'
fetch
'
}
});
Sentry
.
captureException
(
new
Error
(
'
Invalid api token
'
),
{
tags
:
{
source
:
'
invalid_api_token
'
}
});
window
.
location
.
assign
(
loginUrl
);
}
}
...
...
ui/address/details/AddressQrCode.tsx
View file @
813c4dd7
...
...
@@ -26,7 +26,7 @@ const AddressQrCode = ({ hash, className }: Props) => {
QRCode
.
toString
(
hash
,
SVG_OPTIONS
,
(
error
:
Error
|
null
|
undefined
,
svg
:
string
)
=>
{
if
(
error
)
{
setError
(
'
We were unable to generate QR code.
'
);
Sentry
.
captureException
(
error
,
{
tags
:
{
source
:
'
QR
code
'
}
});
Sentry
.
captureException
(
error
,
{
tags
:
{
source
:
'
qr_
code
'
}
});
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment