mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 18:01:07 -05:00
Made interface that represents CurseForge upload error
This commit is contained in:
parent
4739e42f56
commit
4c018de66e
1 changed files with 78 additions and 0 deletions
78
src/platforms/curseforge/curseforge-error.ts
Normal file
78
src/platforms/curseforge/curseforge-error.ts
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
* Error object returned by CurseForge Upload API.
|
||||||
|
*/
|
||||||
|
export interface CurseForgeError {
|
||||||
|
/**
|
||||||
|
* Error code returned by CurseForge Upload API.
|
||||||
|
*/
|
||||||
|
errorCode: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message returned by CurseForge Upload API.
|
||||||
|
*/
|
||||||
|
errorMessage: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an object is a {@link CurseForgeError}.
|
||||||
|
*
|
||||||
|
* @param error - The object to check.
|
||||||
|
*
|
||||||
|
* @returns `true` if the object matches the structure of a CurseForgeError; otherwise, `false`.
|
||||||
|
*/
|
||||||
|
export function isCurseForgeError(error: unknown): error is CurseForgeError {
|
||||||
|
const e = error as CurseForgeError;
|
||||||
|
return (
|
||||||
|
e &&
|
||||||
|
typeof e.errorCode === "number" &&
|
||||||
|
typeof e.errorMessage === "string"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code for an invalid project slug.
|
||||||
|
*/
|
||||||
|
const INVALID_PROJECT_SLUG_ERROR_CODE = 1018;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression to match invalid project slug errors.
|
||||||
|
*/
|
||||||
|
const INVALID_PROJECT_SLUG_REGEX = /Invalid slug in project relations: '([^']*)'/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an error is an invalid project slug error.
|
||||||
|
*
|
||||||
|
* @param error - The error to check.
|
||||||
|
*
|
||||||
|
* @returns `true` if the error is an invalid project slug error; otherwise, `false`.
|
||||||
|
*/
|
||||||
|
export function isInvalidProjectSlugCurseForgeError(error: unknown): error is CurseForgeError {
|
||||||
|
return isCurseForgeError(error) && error.errorCode === INVALID_PROJECT_SLUG_ERROR_CODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the invalid project slug from an error.
|
||||||
|
*
|
||||||
|
* @param error - The error to extract the invalid project slug from.
|
||||||
|
*
|
||||||
|
* @returns The invalid project slug, or `undefined` if the error is not an invalid project slug error.
|
||||||
|
*/
|
||||||
|
export function getInvalidProjectSlug(error: unknown): string | undefined {
|
||||||
|
return isInvalidProjectSlugCurseForgeError(error) ? error.errorMessage.match(INVALID_PROJECT_SLUG_REGEX)?.[1] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code for an invalid game version ID.
|
||||||
|
*/
|
||||||
|
const INVALID_GAME_VERSION_ID_ERROR_CODE = 1009;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an error is an invalid game version ID error.
|
||||||
|
*
|
||||||
|
* @param error - The error to check.
|
||||||
|
*
|
||||||
|
* @returns `true` if the error is an invalid game version ID error; otherwise, `false`.
|
||||||
|
*/
|
||||||
|
export function isInvalidGameVersionIdCurseForgeError(error: unknown): error is CurseForgeError {
|
||||||
|
return isCurseForgeError(error) && error.errorCode === INVALID_GAME_VERSION_ID_ERROR_CODE;
|
||||||
|
}
|
Loading…
Reference in a new issue