partey_workadventure/messages/JsonMessages/ErrorApiData.ts
César Cardinale 97e3397398
Change type of unauthorized (#2123)
* Change type of unauthorized
* Fix redirect on received erroScreenMessage from API
2022-04-26 18:17:12 +02:00

53 lines
1.3 KiB
TypeScript

import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isErrorApiErrorData = z.object({
// @ts-ignore
type: z.literal("error"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
});
export const isErrorApiRetryData = z.object({
type: z.literal("retry"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
buttonTitle: z.optional(z.nullable(z.string())),
timeToRetry: z.number(),
canRetryManual: z.boolean(),
});
export const isErrorApiRedirectData = z.object({
type: z.literal("redirect"),
urlToRedirect: z.string(),
});
export const isErrorApiUnauthorizedData = z.object({
type: z.literal("unauthorized"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
buttonTitle: z.optional(z.nullable(z.string())),
});
export const isErrorApiData = z.discriminatedUnion("type", [
isErrorApiErrorData,
isErrorApiRetryData,
isErrorApiRedirectData,
isErrorApiUnauthorizedData,
]);
export type ErrorApiData = z.infer<typeof isErrorApiData>;