mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-20 16:42:45 +02:00
[Bug] Fix clear ignoring errors from server (#5722)
* Fix clear ignoring errors from server * Update tests to expect a throw
This commit is contained in:
parent
84a2ce979f
commit
ef9a867e67
@ -31,6 +31,7 @@ import ChallengeData from "#app/system/challenge-data";
|
|||||||
import TrainerData from "#app/system/trainer-data";
|
import TrainerData from "#app/system/trainer-data";
|
||||||
import ArenaData from "#app/system/arena-data";
|
import ArenaData from "#app/system/arena-data";
|
||||||
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||||
|
import { MessagePhase } from "./message-phase";
|
||||||
|
|
||||||
export class GameOverPhase extends BattlePhase {
|
export class GameOverPhase extends BattlePhase {
|
||||||
private isVictory: boolean;
|
private isVictory: boolean;
|
||||||
@ -122,7 +123,7 @@ export class GameOverPhase extends BattlePhase {
|
|||||||
globalScene.disableMenu = true;
|
globalScene.disableMenu = true;
|
||||||
globalScene.time.delayedCall(1000, () => {
|
globalScene.time.delayedCall(1000, () => {
|
||||||
let firstClear = false;
|
let firstClear = false;
|
||||||
if (this.isVictory && newClear) {
|
if (this.isVictory) {
|
||||||
if (globalScene.gameMode.isClassic) {
|
if (globalScene.gameMode.isClassic) {
|
||||||
firstClear = globalScene.validateAchv(achvs.CLASSIC_VICTORY);
|
firstClear = globalScene.validateAchv(achvs.CLASSIC_VICTORY);
|
||||||
globalScene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY);
|
globalScene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY);
|
||||||
@ -226,7 +227,17 @@ export class GameOverPhase extends BattlePhase {
|
|||||||
isVictory: this.isVictory,
|
isVictory: this.isVictory,
|
||||||
clientSessionId: clientSessionId,
|
clientSessionId: clientSessionId,
|
||||||
})
|
})
|
||||||
.then(success => doGameOver(!!success));
|
.then(success => doGameOver(!globalScene.gameMode.isDaily || !!success))
|
||||||
|
.catch(_err => {
|
||||||
|
globalScene.clearPhaseQueue();
|
||||||
|
globalScene.clearPhaseQueueSplice();
|
||||||
|
globalScene.unshiftPhase(new MessagePhase(i18next.t("menu:serverCommunicationFailed"), 2500));
|
||||||
|
// force the game to reload after 2 seconds.
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 2000);
|
||||||
|
this.end();
|
||||||
|
});
|
||||||
} else if (this.isVictory) {
|
} else if (this.isVictory) {
|
||||||
globalScene.gameData.offlineNewClear().then(result => {
|
globalScene.gameData.offlineNewClear().then(result => {
|
||||||
doGameOver(result);
|
doGameOver(result);
|
||||||
|
@ -20,17 +20,20 @@ export class PokerogueSessionSavedataApi extends ApiBase {
|
|||||||
* *This is **NOT** the same as {@linkcode clear | clear()}.*
|
* *This is **NOT** the same as {@linkcode clear | clear()}.*
|
||||||
* @param params The {@linkcode NewClearSessionSavedataRequest} to send
|
* @param params The {@linkcode NewClearSessionSavedataRequest} to send
|
||||||
* @returns The raw savedata as `string`.
|
* @returns The raw savedata as `string`.
|
||||||
|
* @throws Error if the request fails
|
||||||
*/
|
*/
|
||||||
public async newclear(params: NewClearSessionSavedataRequest) {
|
public async newclear(params: NewClearSessionSavedataRequest) {
|
||||||
try {
|
try {
|
||||||
const urlSearchParams = this.toUrlSearchParams(params);
|
const urlSearchParams = this.toUrlSearchParams(params);
|
||||||
const response = await this.doGet(`/savedata/session/newclear?${urlSearchParams}`);
|
const response = await this.doGet(`/savedata/session/newclear?${urlSearchParams}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
if (response.ok) {
|
||||||
return Boolean(json);
|
return Boolean(json);
|
||||||
|
}
|
||||||
|
throw new Error("Could not newclear session!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Could not newclear session!", err);
|
console.warn("Could not newclear session!", err);
|
||||||
return false;
|
throw new Error("Could not newclear session!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,7 @@ describe("Pokerogue Session Savedata API", () => {
|
|||||||
it("should return false and report a warning on ERROR", async () => {
|
it("should return false and report a warning on ERROR", async () => {
|
||||||
server.use(http.get(`${apiBase}/savedata/session/newclear`, () => HttpResponse.error()));
|
server.use(http.get(`${apiBase}/savedata/session/newclear`, () => HttpResponse.error()));
|
||||||
|
|
||||||
const success = await sessionSavedataApi.newclear(params);
|
await expect(sessionSavedataApi.newclear(params)).rejects.toThrow("Could not newclear session!");
|
||||||
|
|
||||||
expect(success).toBe(false);
|
|
||||||
expect(console.warn).toHaveBeenCalledWith("Could not newclear session!", expect.any(Error));
|
expect(console.warn).toHaveBeenCalledWith("Could not newclear session!", expect.any(Error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user