-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove ErrorView and navigate to new ErrorScreen instead
Current ErrorView implementation doesn't contains any design so the displayed error is very raw and is not user friendly We want to improve this UI but instead of modifying the ErrorView we replace it by the new generic error page from ErrorScreen. This would improve code homogeneity Also we now use the `navigateToError` function to analyse the error object and chose which error to display
- Loading branch information
Showing
7 changed files
with
87 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import strings from '/constants/strings.json' | ||
import { routes } from '/constants/routes' | ||
import { navigate } from '/libs/RootNavigation' | ||
import { isFetchError } from '/libs/clientHelpers/types' | ||
|
||
/** | ||
* Navigate to the Error page corresponding to the given error | ||
* | ||
* If no dedicated Error page is found for the given error, then | ||
* retidrect to Generic Error page | ||
*/ | ||
export const navigateToError = ( | ||
errorMessage: string, | ||
error: Error, | ||
backgroundColor: string | ||
): void => { | ||
if (isErrorAboutNotOnboardedCozy(error)) { | ||
navigate(routes.error, { | ||
type: strings.errorScreens.cozyNotOnboarded, | ||
backgroundColor | ||
}) | ||
return | ||
} | ||
|
||
if (isErrorAboutBlockedCozy(error)) { | ||
navigate(routes.error, { | ||
type: strings.errorScreens.cozyBlocked, | ||
backgroundColor | ||
}) | ||
return | ||
} | ||
|
||
navigate(routes.error, { | ||
type: strings.errorScreens.genericError, | ||
backgroundColor, | ||
error: { | ||
message: errorMessage, | ||
details: JSON.stringify(error, null, ' ') | ||
} | ||
}) | ||
} | ||
|
||
const isErrorAboutNotOnboardedCozy = (error: unknown): boolean => { | ||
if (!isFetchError(error)) { | ||
return false | ||
} | ||
|
||
return ( | ||
error.status === 412 && | ||
!Array.isArray(error.reason) && | ||
typeof error.reason !== 'string' && | ||
error.reason?.error === 'the instance has not been onboarded' | ||
) | ||
} | ||
|
||
const isErrorAboutBlockedCozy = (error: unknown): boolean => { | ||
if (!isFetchError(error)) { | ||
return false | ||
} | ||
|
||
return ( | ||
error.status === 503 && | ||
Array.isArray(error.reason) && | ||
error.reason.some( | ||
reason => | ||
typeof reason === 'object' && | ||
reason !== null && | ||
'title' in reason && | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
reason.title === 'Blocked' | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.