Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SSHOC
sshoc-marketplace-frontend
Commits
f5bac52f
Commit
f5bac52f
authored
Mar 11, 2021
by
Stefan Probst
Browse files
fix: add default error handlers
parent
36dfd57f
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/components/item/DatasetCreateForm/DatasetCreateForm.tsx
View file @
f5bac52f
...
...
@@ -16,6 +16,7 @@ import { sanitizeFormValues } from '@/lib/sshoc/sanitizeFormValues'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -42,6 +43,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -74,12 +76,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/DatasetEditForm/DatasetEditForm.tsx
View file @
f5bac52f
...
...
@@ -16,6 +16,7 @@ import { sanitizeFormValues } from '@/lib/sshoc/sanitizeFormValues'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -44,6 +45,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -76,12 +78,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/PublicationCreateForm/PublicationCreateForm.tsx
View file @
f5bac52f
...
...
@@ -16,6 +16,7 @@ import { sanitizeFormValues } from '@/lib/sshoc/sanitizeFormValues'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -42,6 +43,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -74,12 +76,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/PublicationEditForm/PublicationEditForm.tsx
View file @
f5bac52f
...
...
@@ -16,6 +16,7 @@ import { sanitizeFormValues } from '@/lib/sshoc/sanitizeFormValues'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -44,6 +45,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -76,12 +78,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/ToolCreateForm/ToolCreateForm.tsx
View file @
f5bac52f
...
...
@@ -14,6 +14,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -40,6 +41,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -72,12 +74,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/ToolEditForm/ToolEditForm.tsx
View file @
f5bac52f
...
...
@@ -14,6 +14,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -42,6 +43,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -74,12 +76,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm.tsx
View file @
f5bac52f
...
...
@@ -14,6 +14,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -40,6 +41,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -72,12 +74,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/TrainingMaterialEditForm/TrainingMaterialEditForm.tsx
View file @
f5bac52f
...
...
@@ -14,6 +14,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -42,6 +43,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
...
...
@@ -74,12 +76,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
router
.
push
({
pathname
:
'
/success
'
})
}
},
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/WorkflowCreateForm/WorkflowCreateForm.tsx
View file @
f5bac52f
...
...
@@ -24,6 +24,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -54,25 +55,34 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
:
false
const
queryClient
=
useQueryClient
()
const
createStep
=
useCreateStep
({
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
stepLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
const
createWorkflow
=
useItemMutation
({
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/components/item/WorkflowEditForm/WorkflowEditForm.tsx
View file @
f5bac52f
...
...
@@ -25,6 +25,7 @@ import { useToast } from '@/elements/Toast/useToast'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
useErrorHandlers
}
from
'
@/modules/error/useErrorHandlers
'
import
{
Form
}
from
'
@/modules/form/Form
'
import
{
getSingularItemCategoryLabel
}
from
'
@/utils/getSingularItemCategoryLabel
'
...
...
@@ -57,32 +58,45 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
useGetLoggedInUser
()
const
handleErrors
=
useErrorHandlers
()
const
isAllowedToPublish
=
user
.
data
?.
role
!==
undefined
?
[
'
administrator
'
,
'
moderator
'
].
includes
(
user
.
data
.
role
)
:
false
const
queryClient
=
useQueryClient
()
const
createStep
=
useCreateStep
({
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
stepLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
const
updateStep
=
useUpdateStep
({
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
stepLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
const
updateWorkflow
=
useItemMutation
({
onError
()
{
onError
(
error
)
{
toast
.
error
(
`Failed to
${
isAllowedToPublish
?
'
publish
'
:
'
submit
'
}
${
categoryLabel
}
.`
,
)
if
(
error
instanceof
Error
)
{
handleErrors
(
error
)
}
},
})
...
...
src/modules/error/useErrorHandlers.ts
0 → 100644
View file @
f5bac52f
import
{
HttpError
}
from
'
@/api/sshoc
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
export
function
useErrorHandlers
():
(
error
:
Error
)
=>
void
{
const
auth
=
useAuth
()
function
handle
(
error
:
Error
)
{
if
(
error
instanceof
HttpError
)
{
switch
(
error
.
statusCode
)
{
case
401
:
case
403
:
auth
.
signOut
()
break
}
}
}
return
handle
}
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