diff --git a/src/session/index.ts b/src/session/index.ts index 7b0400d..f538754 100644 --- a/src/session/index.ts +++ b/src/session/index.ts @@ -163,28 +163,36 @@ export class Session { } public readPronoteFunctionPayload (response_body: string): Res { - if (response_body.includes("La page a expir")) { - throw new Error("The page has expired."); - } + let response: PronoteApiFunctionPayload; - if (response_body.includes("Votre adresse IP a ")) { - throw new Error("Your IP address is temporarily suspended."); + try { + response = JSON.parse(response_body); } + catch { + if (response_body.includes("La page a expir")) { + throw new Error("The page has expired."); + } - if (response_body.includes("La page dem")) { - throw new Error("The requested page does not exist."); - } + else if (response_body.includes("Votre adresse IP a ")) { + throw new Error("Your IP address is temporarily suspended."); + } - if (response_body.includes("Impossible d'a")) { - throw new Error("Page unaccessible."); - } + else if (response_body.includes("La page dem")) { + throw new Error("The requested page does not exist."); + } + + else if (response_body.includes("Impossible d'a")) { + throw new Error("Page unaccessible."); + } + + else if (response_body.includes("Vous avez d")) { + throw new Error("You've been rate-limited."); + } - if (response_body.includes("Vous avez d")) { - throw new Error("You've been rate-limited."); + throw new Error("Failed to parse JSON from response."); } this.instance.order++; - const response = JSON.parse(response_body) as PronoteApiFunctionPayload; try { // Check the local order number with the received one.