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 ArenaData from "#app/system/arena-data";
|
||||
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||
import { MessagePhase } from "./message-phase";
|
||||
|
||||
export class GameOverPhase extends BattlePhase {
|
||||
private isVictory: boolean;
|
||||
@ -122,7 +123,7 @@ export class GameOverPhase extends BattlePhase {
|
||||
globalScene.disableMenu = true;
|
||||
globalScene.time.delayedCall(1000, () => {
|
||||
let firstClear = false;
|
||||
if (this.isVictory && newClear) {
|
||||
if (this.isVictory) {
|
||||
if (globalScene.gameMode.isClassic) {
|
||||
firstClear = globalScene.validateAchv(achvs.CLASSIC_VICTORY);
|
||||
globalScene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY);
|
||||
@ -226,7 +227,17 @@ export class GameOverPhase extends BattlePhase {
|
||||
isVictory: this.isVictory,
|
||||
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) {
|
||||
globalScene.gameData.offlineNewClear().then(result => {
|
||||
doGameOver(result);
|
||||
|
@ -20,17 +20,20 @@ export class PokerogueSessionSavedataApi extends ApiBase {
|
||||
* *This is **NOT** the same as {@linkcode clear | clear()}.*
|
||||
* @param params The {@linkcode NewClearSessionSavedataRequest} to send
|
||||
* @returns The raw savedata as `string`.
|
||||
* @throws Error if the request fails
|
||||
*/
|
||||
public async newclear(params: NewClearSessionSavedataRequest) {
|
||||
try {
|
||||
const urlSearchParams = this.toUrlSearchParams(params);
|
||||
const response = await this.doGet(`/savedata/session/newclear?${urlSearchParams}`);
|
||||
const json = await response.json();
|
||||
|
||||
return Boolean(json);
|
||||
if (response.ok) {
|
||||
return Boolean(json);
|
||||
}
|
||||
throw new Error("Could not newclear session!");
|
||||
} catch (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 () => {
|
||||
server.use(http.get(`${apiBase}/savedata/session/newclear`, () => HttpResponse.error()));
|
||||
|
||||
const success = await sessionSavedataApi.newclear(params);
|
||||
|
||||
expect(success).toBe(false);
|
||||
await expect(sessionSavedataApi.newclear(params)).rejects.toThrow("Could not newclear session!");
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not newclear session!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user