fix: stabilize competition results flow
This commit is contained in:
1 parent
3bd3120eb1
commit
a88562b208
20 files changed
+411
-65
No files matched your search
@@ -26,15 +26,24 @@ export function isConsistentTeamProgressSnapshot(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A visitor who is not signed in (401) — or is signed in but belongs to no team
|
||||
* in this Competition (403) — can still read a team view by naming the team.
|
||||
* Offer the team picker instead of an error until they have named one.
|
||||
*/
|
||||
export function shouldOfferTeamSelection(
|
||||
errors: readonly unknown[],
|
||||
selectedTeamId: string | undefined,
|
||||
): boolean {
|
||||
if (selectedTeamId) return false;
|
||||
const statuses = errorStatuses(errors);
|
||||
return statuses.includes(401) || statuses.includes(403);
|
||||
}
|
||||
|
||||
export function getTeamProgressErrorContent(
|
||||
errors: readonly unknown[],
|
||||
): TeamProgressErrorContent {
|
||||
const statuses = errors.flatMap((error) => {
|
||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
||||
return [];
|
||||
}
|
||||
return typeof error.status === "number" ? [error.status] : [];
|
||||
});
|
||||
const statuses = errorStatuses(errors);
|
||||
|
||||
if (statuses.includes(401)) {
|
||||
return {
|
||||
@@ -86,6 +95,15 @@ export function getTeamProgressErrorContent(
|
||||
};
|
||||
}
|
||||
|
||||
function errorStatuses(errors: readonly unknown[]): number[] {
|
||||
return errors.flatMap((error) => {
|
||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
||||
return [];
|
||||
}
|
||||
return typeof error.status === "number" ? [error.status] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function isNetworkError(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof TypeError ||
|
||||
|
||||
Reference in new issue
Block a user