cleanup of new result code
This commit is contained in:
parent
498e2611ae
commit
5a032a87ae
23 changed files with 323 additions and 303 deletions
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { BoardGameModel } from 'packages/obsidian/src/models/BoardGameModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -25,12 +25,12 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
this.types = [MediaType.BoardGame];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.BoardgameGeekKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -46,8 +46,8 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
},
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -61,7 +61,7 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
|
||||
if (fetchData.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -70,7 +70,7 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status },
|
||||
|
|
@ -103,12 +103,12 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.BoardgameGeekKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -124,8 +124,8 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
},
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -139,7 +139,7 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
|
||||
if (fetchData.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -148,7 +148,7 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status, id },
|
||||
|
|
@ -162,7 +162,7 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
const boardgame = response.querySelector('boardgame');
|
||||
if (!boardgame) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received invalid data from ${this.apiName}.`,
|
||||
userMessage: `Received invalid data from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { ComicMangaModel } from 'packages/obsidian/src/models/ComicMangaModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -27,12 +27,12 @@ export class ComicVineAPI extends APIModel {
|
|||
this.types = [MediaType.ComicManga];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.ComicVineKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -45,8 +45,8 @@ export class ComicVineAPI extends APIModel {
|
|||
url: searchUrl,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -59,7 +59,7 @@ export class ComicVineAPI extends APIModel {
|
|||
// console.debug(fetchData);
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status },
|
||||
|
|
@ -85,12 +85,12 @@ export class ComicVineAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.ComicVineKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -103,8 +103,8 @@ export class ComicVineAPI extends APIModel {
|
|||
url: searchUrl,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -119,7 +119,7 @@ export class ComicVineAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { GameModel } from 'packages/obsidian/src/models/GameModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -60,7 +60,7 @@ export class IGDBAPI extends APIModel {
|
|||
this.types = [MediaType.Game];
|
||||
}
|
||||
|
||||
private async getAuthToken(): Promise<Result<string, AppError>> {
|
||||
private async getAuthToken(): Promise<Result<string, MDBError>> {
|
||||
const currentTime = Date.now();
|
||||
if (this.accessToken && currentTime < this.tokenExpiry) return ok(this.accessToken);
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ export class IGDBAPI extends APIModel {
|
|||
|
||||
if (!clientId || !clientSecret) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | Client ID or Client Secret for ${this.apiName} missing.`,
|
||||
userMessage: `Client ID or Client Secret for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -82,8 +82,8 @@ export class IGDBAPI extends APIModel {
|
|||
method: 'POST',
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying Twitch auth for ${this.apiName}`,
|
||||
userMessage: `Network error querying Twitch auth for ${this.apiName}`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -96,7 +96,7 @@ export class IGDBAPI extends APIModel {
|
|||
const response = responseResult.value;
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Auth failed for ${this.apiName}. Check Credentials.`,
|
||||
userMessage: `Auth failed for ${this.apiName}. Check Credentials.`,
|
||||
context: { apiName: this.apiName, status: response.status },
|
||||
|
|
@ -109,12 +109,12 @@ export class IGDBAPI extends APIModel {
|
|||
return ok(this.accessToken);
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const clientId = this.plugin.app.secretStorage.getSecret(this.plugin.settings.IGDBClientId);
|
||||
if (!clientId) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | Client ID for ${this.apiName} missing.`,
|
||||
userMessage: `Client ID for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -134,8 +134,8 @@ export class IGDBAPI extends APIModel {
|
|||
body: queryBody,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -147,7 +147,7 @@ export class IGDBAPI extends APIModel {
|
|||
const response = responseResult.value;
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status },
|
||||
|
|
@ -172,12 +172,12 @@ export class IGDBAPI extends APIModel {
|
|||
);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const clientId = this.plugin.app.secretStorage.getSecret(this.plugin.settings.IGDBClientId);
|
||||
if (!clientId) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | Client ID for ${this.apiName} missing.`,
|
||||
userMessage: `Client ID for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -197,8 +197,8 @@ export class IGDBAPI extends APIModel {
|
|||
body: queryBody,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -210,7 +210,7 @@ export class IGDBAPI extends APIModel {
|
|||
const response = responseResult.value;
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status, id },
|
||||
|
|
@ -220,7 +220,7 @@ export class IGDBAPI extends APIModel {
|
|||
const data = response.json as IGDBGame[];
|
||||
if (!data || data.length === 0) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No result found for ID ${id}`,
|
||||
userMessage: `No result found for ID ${id}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import type MediaDbPlugin from 'packages/obsidian/src/main';
|
|||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { MovieModel } from 'packages/obsidian/src/models/MovieModel';
|
||||
import { SeriesModel } from 'packages/obsidian/src/models/SeriesModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -33,7 +33,7 @@ export class MALAPI extends APIModel {
|
|||
this.typeMappings.set('ova', 'ova');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://api.jikan.moe/v4/' });
|
||||
|
|
@ -51,7 +51,7 @@ export class MALAPI extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status },
|
||||
|
|
@ -108,7 +108,7 @@ export class MALAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://api.jikan.moe/v4/' });
|
||||
|
|
@ -124,7 +124,7 @@ export class MALAPI extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status, id },
|
||||
|
|
@ -135,7 +135,7 @@ export class MALAPI extends APIModel {
|
|||
|
||||
if (result === undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data found for ID ${id} in ${this.apiName}.`,
|
||||
userMessage: `No data found for ID ${id} in ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -248,7 +248,7 @@ export class MALAPI extends APIModel {
|
|||
}
|
||||
|
||||
return err({
|
||||
kind: AppErrorKind.Unexpected,
|
||||
kind: MDBErrorKind.Unexpected,
|
||||
message: `MDB | Unknown media type for id ${id}`,
|
||||
userMessage: `Unknown media type for id ${id}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { ComicMangaModel } from 'packages/obsidian/src/models/ComicMangaModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -35,7 +35,7 @@ export class MALAPIManga extends APIModel {
|
|||
this.typeMappings.set('novel', 'novel');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://api.jikan.moe/v4/' });
|
||||
|
|
@ -53,7 +53,7 @@ export class MALAPIManga extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status },
|
||||
|
|
@ -106,7 +106,7 @@ export class MALAPIManga extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://api.jikan.moe/v4/' });
|
||||
|
|
@ -122,7 +122,7 @@ export class MALAPIManga extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status, id },
|
||||
|
|
@ -133,7 +133,7 @@ export class MALAPIManga extends APIModel {
|
|||
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data found for ID ${id} in ${this.apiName}.`,
|
||||
userMessage: `No data found for ID ${id} in ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { MusicReleaseModel } from 'packages/obsidian/src/models/MusicReleaseModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -108,7 +108,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
this.types = [MediaType.MusicRelease];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `https://musicbrainz.org/ws/2/release-group?query=${encodeURIComponent(title)}&limit=20&fmt=json`;
|
||||
|
|
@ -121,8 +121,8 @@ export class MusicBrainzAPI extends APIModel {
|
|||
},
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -137,7 +137,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status },
|
||||
|
|
@ -172,7 +172,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
// Fetch release group
|
||||
|
|
@ -185,8 +185,8 @@ export class MusicBrainzAPI extends APIModel {
|
|||
},
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -199,7 +199,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
|
||||
if (groupResponse.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${groupResponse.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${groupResponse.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: groupResponse.status, id },
|
||||
|
|
@ -212,7 +212,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
const firstRelease = result.releases?.[0];
|
||||
if (!firstRelease) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | No releases found in release group.',
|
||||
userMessage: 'No releases found in release group.',
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -231,8 +231,8 @@ export class MusicBrainzAPI extends APIModel {
|
|||
},
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id, releaseId: firstRelease.id },
|
||||
|
|
@ -245,7 +245,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
|
||||
if (releaseResponse.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${releaseResponse.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${releaseResponse.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: releaseResponse.status, id, releaseId: firstRelease.id },
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { GameModel } from 'packages/obsidian/src/models/GameModel';
|
|||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { MovieModel } from 'packages/obsidian/src/models/MovieModel';
|
||||
import { SeriesModel } from 'packages/obsidian/src/models/SeriesModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -79,13 +79,13 @@ export class OMDbAPI extends APIModel {
|
|||
this.typeMappings.set('game', 'game');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.OMDbKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -98,8 +98,8 @@ export class OMDbAPI extends APIModel {
|
|||
method: 'GET',
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -113,7 +113,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
if (response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -121,7 +121,7 @@ export class OMDbAPI extends APIModel {
|
|||
}
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status },
|
||||
|
|
@ -132,7 +132,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
if (!data) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -145,7 +145,7 @@ export class OMDbAPI extends APIModel {
|
|||
}
|
||||
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received error from ${this.apiName}: ${data.Error}`,
|
||||
userMessage: `${data.Error}`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -203,13 +203,13 @@ export class OMDbAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.OMDbKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -222,8 +222,8 @@ export class OMDbAPI extends APIModel {
|
|||
method: 'GET',
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -237,7 +237,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
if (response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -245,7 +245,7 @@ export class OMDbAPI extends APIModel {
|
|||
}
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status, id },
|
||||
|
|
@ -256,7 +256,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -265,7 +265,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
if (result.Response === 'False') {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received error from ${this.apiName}: ${result.Error}`,
|
||||
userMessage: `${result.Error}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -275,7 +275,7 @@ export class OMDbAPI extends APIModel {
|
|||
const type = this.typeMappings.get(result.Type.toLowerCase());
|
||||
if (type === undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `${result.Type.toLowerCase()} is an unsupported type.`,
|
||||
userMessage: `${result.Type.toLowerCase()} is an unsupported type.`,
|
||||
context: { apiName: this.apiName, id, type: result.Type },
|
||||
|
|
@ -375,7 +375,7 @@ export class OMDbAPI extends APIModel {
|
|||
}
|
||||
|
||||
return err({
|
||||
kind: AppErrorKind.Unexpected,
|
||||
kind: MDBErrorKind.Unexpected,
|
||||
message: `MDB | Unknown media type for id ${id}`,
|
||||
userMessage: `Unknown media type for id ${id}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { BookModel } from 'packages/obsidian/src/models/BookModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -48,7 +48,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
this.types = [MediaType.Book];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://openlibrary.org/' });
|
||||
|
|
@ -63,8 +63,8 @@ export class OpenLibraryAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -78,7 +78,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status },
|
||||
|
|
@ -109,7 +109,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const client = createClient<paths>({ baseUrl: 'https://openlibrary.org/' });
|
||||
|
|
@ -125,8 +125,8 @@ export class OpenLibraryAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -140,7 +140,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
|
||||
if (response.error !== undefined) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status, id },
|
||||
|
|
@ -155,7 +155,7 @@ export class OpenLibraryAPI extends APIModel {
|
|||
const result = data.docs?.[0];
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data found for ID ${id} in ${this.apiName}.`,
|
||||
userMessage: `No data found for ID ${id}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { GameModel } from 'packages/obsidian/src/models/GameModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -40,11 +40,11 @@ export class RAWGAPI extends APIModel {
|
|||
this.types = [MediaType.Game];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.RAWGAPIKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -57,8 +57,8 @@ export class RAWGAPI extends APIModel {
|
|||
method: 'GET',
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -71,7 +71,7 @@ export class RAWGAPI extends APIModel {
|
|||
const response = responseResult.value;
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Error ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Error ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status },
|
||||
|
|
@ -95,11 +95,11 @@ export class RAWGAPI extends APIModel {
|
|||
);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.RAWGAPIKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -112,8 +112,8 @@ export class RAWGAPI extends APIModel {
|
|||
method: 'GET',
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -126,7 +126,7 @@ export class RAWGAPI extends APIModel {
|
|||
const response = responseResult.value;
|
||||
if (response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Error ${response.status} from ${this.apiName}.`,
|
||||
userMessage: `Error ${response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.status, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { GameModel } from 'packages/obsidian/src/models/GameModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -148,7 +148,7 @@ export class SteamAPI extends APIModel {
|
|||
this.typeMappings.set('game', 'game');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `https://steamcommunity.com/actions/SearchApps/${encodeURIComponent(title)}`;
|
||||
|
|
@ -157,8 +157,8 @@ export class SteamAPI extends APIModel {
|
|||
url: searchUrl,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -171,7 +171,7 @@ export class SteamAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status },
|
||||
|
|
@ -200,7 +200,7 @@ export class SteamAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `https://store.steampowered.com/api/appdetails?appids=${encodeURIComponent(id)}&l=en`;
|
||||
|
|
@ -209,8 +209,8 @@ export class SteamAPI extends APIModel {
|
|||
url: searchUrl,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -223,7 +223,7 @@ export class SteamAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status, id },
|
||||
|
|
@ -242,7 +242,7 @@ export class SteamAPI extends APIModel {
|
|||
}
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | API returned invalid data.',
|
||||
userMessage: 'Steam returned invalid data.',
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -254,8 +254,8 @@ export class SteamAPI extends APIModel {
|
|||
// Check if a poster version of the image exists, else use the header image
|
||||
const imageUrl = `https://steamcdn-a.akamaihd.net/steam/apps/${result.steam_appid}/library_600x900_2x.jpg`;
|
||||
const existsResult = await fromPromise(imageUrlExists(imageUrl), cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Failed to validate image URL for ${this.apiName}`,
|
||||
userMessage: `Failed to validate image URL for ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id, imageUrl },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { MovieModel } from 'packages/obsidian/src/models/MovieModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -59,13 +59,13 @@ export class TMDBMovieAPI extends APIModel {
|
|||
this.typeMappings.set('movie', 'movie');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -87,8 +87,8 @@ export class TMDBMovieAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -103,7 +103,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
|
||||
if (response.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -111,7 +111,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
}
|
||||
if (response.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status },
|
||||
|
|
@ -122,7 +122,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
|
||||
if (!data) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -153,13 +153,13 @@ export class TMDBMovieAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -181,8 +181,8 @@ export class TMDBMovieAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -197,7 +197,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
|
||||
if (response.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -205,7 +205,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
}
|
||||
if (response.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status, id },
|
||||
|
|
@ -216,7 +216,7 @@ export class TMDBMovieAPI extends APIModel {
|
|||
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { SeasonModel } from 'packages/obsidian/src/models/SeasonModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -63,13 +63,13 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
this.typeMappings.set('tv', 'season');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -91,8 +91,8 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -106,7 +106,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (searchResponse.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -115,7 +115,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (searchResponse.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${searchResponse.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${searchResponse.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: searchResponse.response.status },
|
||||
|
|
@ -169,11 +169,11 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
}
|
||||
|
||||
// Fetch all seasons for a given series
|
||||
async getSeasonsForSeries(tvId: string): Promise<Result<SeasonModel[], AppError>> {
|
||||
async getSeasonsForSeries(tvId: string): Promise<Result<SeasonModel[], MDBError>> {
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName, tvId },
|
||||
|
|
@ -192,8 +192,8 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, tvId },
|
||||
|
|
@ -207,7 +207,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seriesResponse.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName, tvId },
|
||||
|
|
@ -216,7 +216,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seriesResponse.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${seriesResponse.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${seriesResponse.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: seriesResponse.response.status, tvId },
|
||||
|
|
@ -250,13 +250,13 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -267,7 +267,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
const m = /^(\d+)\/season\/(\d+)$/.exec(id);
|
||||
if (!m) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | Invalid season id "${id}". Expected format "<series_id>/season/<season_number>".`,
|
||||
userMessage: `Invalid season id "${id}".`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -294,8 +294,8 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -309,7 +309,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seasonResponse.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -318,7 +318,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seasonResponse.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${seasonResponse.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${seasonResponse.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: seasonResponse.response.status, id },
|
||||
|
|
@ -328,7 +328,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
const seasonData = seasonResponse.data;
|
||||
if (!seasonData) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -349,8 +349,8 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -364,7 +364,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seriesResponse.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -373,7 +373,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (seriesResponse.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${seriesResponse.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${seriesResponse.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: seriesResponse.response.status, id },
|
||||
|
|
@ -384,7 +384,7 @@ export class TMDBSeasonAPI extends APIModel {
|
|||
|
||||
if (!seriesData) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { SeriesModel } from 'packages/obsidian/src/models/SeriesModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -50,13 +50,13 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
this.typeMappings.set('tv', 'series');
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -78,8 +78,8 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, title },
|
||||
|
|
@ -93,7 +93,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
|
||||
if (response.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -101,7 +101,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
}
|
||||
if (response.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status },
|
||||
|
|
@ -112,7 +112,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
|
||||
if (!data) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -143,13 +143,13 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
const key = this.plugin.app.secretStorage.getSecret(this.plugin.settings.TMDBKeyId);
|
||||
|
||||
if (!key) {
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | API key for ${this.apiName} missing.`,
|
||||
userMessage: `API key for ${this.apiName} missing.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -171,8 +171,8 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
fetch: obsidianFetch,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -186,7 +186,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
|
||||
if (response.response.status === 401) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
userMessage: `Authentication for ${this.apiName} failed. Check the API key.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -194,7 +194,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
}
|
||||
if (response.response.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${response.response.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: response.response.status, id },
|
||||
|
|
@ -205,7 +205,7 @@ export class TMDBSeriesAPI extends APIModel {
|
|||
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import { GameModel } from 'packages/obsidian/src/models/GameModel';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -110,7 +110,7 @@ export class VNDBAPI extends APIModel {
|
|||
* @returns A JSON object representing the query response.
|
||||
* @see {@link https://api.vndb.org/kana#api-structure}
|
||||
*/
|
||||
private async postQuery(endpoint: string, body: string): Promise<Result<unknown, AppError>> {
|
||||
private async postQuery(endpoint: string, body: string): Promise<Result<unknown, MDBError>> {
|
||||
const fetchDataResult = await fromPromise(
|
||||
requestUrl({
|
||||
url: `${this.apiUrl}${endpoint}`,
|
||||
|
|
@ -120,8 +120,8 @@ export class VNDBAPI extends APIModel {
|
|||
throw: false,
|
||||
}),
|
||||
cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Network error querying ${this.apiName}`,
|
||||
userMessage: `Network error querying ${this.apiName}`,
|
||||
context: { apiName: this.apiName, endpoint },
|
||||
|
|
@ -136,42 +136,42 @@ export class VNDBAPI extends APIModel {
|
|||
switch (fetchData.status) {
|
||||
case 400:
|
||||
return err({
|
||||
kind: AppErrorKind.Validation,
|
||||
kind: MDBErrorKind.Validation,
|
||||
message: `MDB | Invalid request body or query [${fetchData.text}].`,
|
||||
userMessage: 'Invalid VNDB request.',
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
});
|
||||
case 404:
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | Invalid API path or HTTP method.',
|
||||
userMessage: 'VNDB endpoint not found.',
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
});
|
||||
case 429:
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | VNDB throttled the request.',
|
||||
userMessage: 'VNDB throttled the request. Please try again later.',
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
});
|
||||
case 500:
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | VNDB server error.',
|
||||
userMessage: 'VNDB server error.',
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
});
|
||||
case 502:
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: 'MDB | VNDB server is down.',
|
||||
userMessage: 'VNDB server is down.',
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
});
|
||||
default:
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, endpoint, status: fetchData.status },
|
||||
|
|
@ -187,7 +187,7 @@ export class VNDBAPI extends APIModel {
|
|||
* Queries visual novel entries.
|
||||
* @see {@link https://api.vndb.org/kana#post-vn}
|
||||
*/
|
||||
private async postVNQuery(body: string): Promise<Result<VNJSONResponse, AppError>> {
|
||||
private async postVNQuery(body: string): Promise<Result<VNJSONResponse, MDBError>> {
|
||||
const result = await this.postQuery('/vn', body);
|
||||
return result.ok ? ok(result.value as VNJSONResponse) : err(result.error);
|
||||
}
|
||||
|
|
@ -197,12 +197,12 @@ export class VNDBAPI extends APIModel {
|
|||
* Queries release entries.
|
||||
* @see {@link https://api.vndb.org/kana#post-release}
|
||||
*/
|
||||
private async postReleaseQuery(body: string): Promise<Result<ReleaseJSONResponse, AppError>> {
|
||||
private async postReleaseQuery(body: string): Promise<Result<ReleaseJSONResponse, MDBError>> {
|
||||
const result = await this.postQuery('/release', body);
|
||||
return result.ok ? ok(result.value as ReleaseJSONResponse) : err(result.error);
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
/* SFW Filter: has ANY official&&complete&&standalone&&SFW release
|
||||
|
|
@ -253,7 +253,7 @@ export class VNDBAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const vnDataResult = await this.postVNQuery(`{
|
||||
|
|
@ -267,7 +267,7 @@ export class VNDBAPI extends APIModel {
|
|||
|
||||
if (vnData.results.length !== 1) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Expected 1 result from query, got ${vnData.results.length}.`,
|
||||
userMessage: 'Unexpected VNDB response.',
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { APIModel } from 'packages/obsidian/src/api/APIModel';
|
|||
import type MediaDbPlugin from 'packages/obsidian/src/main';
|
||||
import type { MediaTypeModel } from 'packages/obsidian/src/models/MediaTypeModel';
|
||||
import { WikiModel } from 'packages/obsidian/src/models/WikiModel';
|
||||
import type { AppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { AppErrorKind, toAppError } from 'packages/obsidian/src/utils/AppError';
|
||||
import { Logger } from 'packages/obsidian/src/utils/Logger';
|
||||
import type { MDBError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MDBErrorKind, toMdbError } from 'packages/obsidian/src/utils/MDBError';
|
||||
import { MediaType } from 'packages/obsidian/src/utils/MediaType';
|
||||
import type { Result } from 'packages/obsidian/src/utils/result';
|
||||
import { err, fromPromise, ok } from 'packages/obsidian/src/utils/result';
|
||||
|
|
@ -53,7 +53,7 @@ export class WikipediaAPI extends APIModel {
|
|||
this.types = [MediaType.Wiki];
|
||||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], AppError>> {
|
||||
async searchByTitle(title: string): Promise<Result<MediaTypeModel[], MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(title)}&srlimit=20&utf8=&format=json&origin=*`;
|
||||
|
|
@ -66,7 +66,7 @@ export class WikipediaAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status },
|
||||
|
|
@ -75,8 +75,8 @@ export class WikipediaAPI extends APIModel {
|
|||
|
||||
const response = fetchData as { status: number; json(): Promise<unknown> };
|
||||
const dataResult = await fromPromise(response.json(), cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Failed to parse response from ${this.apiName}`,
|
||||
userMessage: `Failed to parse response from ${this.apiName}`,
|
||||
context: { apiName: this.apiName },
|
||||
|
|
@ -105,7 +105,7 @@ export class WikipediaAPI extends APIModel {
|
|||
return ok(ret);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, AppError>> {
|
||||
async getById(id: string): Promise<Result<MediaTypeModel, MDBError>> {
|
||||
Logger.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&prop=info&pageids=${encodeURIComponent(id)}&inprop=url&format=json&origin=*`;
|
||||
|
|
@ -117,7 +117,7 @@ export class WikipediaAPI extends APIModel {
|
|||
|
||||
if (fetchData.status !== 200) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
userMessage: `Received status code ${fetchData.status} from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, status: fetchData.status, id },
|
||||
|
|
@ -126,8 +126,8 @@ export class WikipediaAPI extends APIModel {
|
|||
|
||||
const response = fetchData as { status: number; json(): Promise<unknown> };
|
||||
const dataResult = await fromPromise(response.json(), cause =>
|
||||
toAppError(cause, {
|
||||
kind: AppErrorKind.Network,
|
||||
toMdbError(cause, {
|
||||
kind: MDBErrorKind.Network,
|
||||
message: `MDB | Failed to parse response from ${this.apiName}`,
|
||||
userMessage: `Failed to parse response from ${this.apiName}`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
@ -141,7 +141,7 @@ export class WikipediaAPI extends APIModel {
|
|||
const result = Object.values(data?.query?.pages)[0];
|
||||
if (!result) {
|
||||
return err({
|
||||
kind: AppErrorKind.Api,
|
||||
kind: MDBErrorKind.Api,
|
||||
message: `MDB | No data received from ${this.apiName}.`,
|
||||
userMessage: `No data received from ${this.apiName}.`,
|
||||
context: { apiName: this.apiName, id },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue