Skip to content

Commit

Permalink
fix(session): do string search only if JSON is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited authored Feb 21, 2024
1 parent 8e29471 commit 3d491e9
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,36 @@ export class Session {
}

public readPronoteFunctionPayload <Res>(response_body: string): Res {
if (response_body.includes("La page a expir")) {
throw new Error("The page has expired.");
}
let response: PronoteApiFunctionPayload<Res>;

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<Res>;

try {
// Check the local order number with the received one.
Expand Down

0 comments on commit 3d491e9

Please sign in to comment.