mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: user error discrimination
This commit is contained in:
1 parent
f9e0584f00
commit
4b00e1342e
11 files changed
+49
-51
No files matched your search
@@ -1,5 +1,3 @@
|
||||
import throwError from '../blitzkrieg/throwError';
|
||||
|
||||
export type BlitzResponse<Data extends object> =
|
||||
| {
|
||||
status: 'error';
|
||||
@@ -18,9 +16,8 @@ export default async function fetchBlitz<Data extends object>(url: string) {
|
||||
if (data.status === 'ok') {
|
||||
return data.data;
|
||||
} else {
|
||||
throw throwError(
|
||||
`Wargaming response error status:"${data.status}"`,
|
||||
`Message: "${data.error.message}"\nURL: "${url}"`,
|
||||
);
|
||||
throw new Error(`Wargaming response error status:"${data.status}"`, {
|
||||
cause: `Message: "${data.error.message}"\nURL: "${url}"`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { TanksStats } from '../../types/tanksStats';
|
||||
import throwError from '../blitzkrieg/throwError';
|
||||
import { UserError } from '../blitzkrieg/userError';
|
||||
import fetchBlitz from './fetchWargaming';
|
||||
|
||||
export default async function getTankStats(region: Region, id: number) {
|
||||
@@ -10,10 +10,10 @@ export default async function getTankStats(region: Region, id: number) {
|
||||
);
|
||||
|
||||
if (tankStats[id] === null) {
|
||||
throw throwError(
|
||||
'No tank stats available',
|
||||
"This player doesn't have any stats for tanks available. This may not be the player you are looking for.",
|
||||
);
|
||||
throw new UserError('No tank stats available', {
|
||||
cause:
|
||||
"This player doesn't have any stats for tanks available. This may not be the player you are looking for.",
|
||||
});
|
||||
}
|
||||
|
||||
return tankStats[id];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { go } from 'fuzzysort';
|
||||
import throwError from '../blitzkrieg/throwError';
|
||||
import { UserError } from '../blitzkrieg/userError';
|
||||
import { TANKS, tankopedia } from '../blitzstars/tankopedia';
|
||||
|
||||
export default async function resolveTankId(tank: string | number) {
|
||||
@@ -12,10 +12,9 @@ export default async function resolveTankId(tank: string | number) {
|
||||
});
|
||||
|
||||
if (searchResult.length === 0) {
|
||||
throw throwError(
|
||||
'Tank not found',
|
||||
`Could not find tank by the name "${tank}".`,
|
||||
);
|
||||
throw new UserError('Tank not found', {
|
||||
cause: `Could not find tank by the name "${tank}".`,
|
||||
});
|
||||
} else {
|
||||
return searchResult[0].obj.tank_id;
|
||||
}
|
||||
@@ -23,10 +22,9 @@ export default async function resolveTankId(tank: string | number) {
|
||||
if ((await tankopedia)[number]) {
|
||||
return number;
|
||||
} else {
|
||||
throw throwError(
|
||||
'Tank not found',
|
||||
`Could not find tank by the ID "${number}".`,
|
||||
);
|
||||
throw new UserError('Tank not found', {
|
||||
cause: `Could not find tank by the ID "${number}".`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user