ecoledirecte-api-types
Version:
If you need a EcoleDirecte client for JavaScript, this isn't the right place! This way: [ecoledirecte.js](https://github.com/a2br/ecoledirecte.js).
24 lines (23 loc) • 526 B
text/typescript
export type failureRes = {
code: number;
token: string;
host?: string;
message: string;
data?: {
accounts?: [];
};
};
export function isFailure(data: Record<string, unknown>): data is failureRes {
try {
const usualError = !data.token && data.code !== 200;
const blockError =
typeof data.message === "string"
? data.code === 403 &&
(data as { message: string }).message.includes("votre adresse IP")
: false;
const error = usualError || blockError;
return error;
} catch {
return true;
}
}