[Bug][Localhost] fix Json parse issue when trying to load battle-anim (#3455)
* add content-type check for loading battle-anims * add missing `headers` to response mocks
This commit is contained in:
parent
bfdcd4fc1e
commit
762feea332
|
@ -485,7 +485,8 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise<void> {
|
||||||
const fetchAnimAndResolve = (move: Moves) => {
|
const fetchAnimAndResolve = (move: Moves) => {
|
||||||
scene.cachedFetch(`./battle-anims/${moveName}.json`)
|
scene.cachedFetch(`./battle-anims/${moveName}.json`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
const contentType = response.headers.get("content-type");
|
||||||
|
if (!response.ok || contentType?.indexOf("application/json") === -1) {
|
||||||
console.error(`Could not load animation file for move '${moveName}'`, response.status, response.statusText);
|
console.error(`Could not load animation file for move '${moveName}'`, response.status, response.statusText);
|
||||||
populateMoveAnim(move, moveAnims.get(defaultMoveAnim));
|
populateMoveAnim(move, moveAnims.get(defaultMoveAnim));
|
||||||
return resolve();
|
return resolve();
|
||||||
|
|
|
@ -242,6 +242,7 @@ function createFetchResponse(data) {
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 200,
|
status: 200,
|
||||||
|
headers: new Headers(),
|
||||||
json: () => Promise.resolve(data),
|
json: () => Promise.resolve(data),
|
||||||
text: () => Promise.resolve(JSON.stringify(data)),
|
text: () => Promise.resolve(JSON.stringify(data)),
|
||||||
};
|
};
|
||||||
|
@ -251,6 +252,7 @@ function createFetchBadResponse(data) {
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: 404,
|
status: 404,
|
||||||
|
headers: new Headers(),
|
||||||
json: () => Promise.resolve(data),
|
json: () => Promise.resolve(data),
|
||||||
text: () => Promise.resolve(JSON.stringify(data)),
|
text: () => Promise.resolve(JSON.stringify(data)),
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,10 +23,13 @@ export const MockFetch = (input, init) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
const response: Partial<Response> = {
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 200,
|
status: 200,
|
||||||
json: responseHandler,
|
json: responseHandler,
|
||||||
text: responseText,
|
text: responseText,
|
||||||
});
|
headers: new Headers({}),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Promise.resolve(response);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue