mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 14:06:29 +01:00
add error classes to libs + adjust existing imports #3
This commit is contained in:
parent
6b61bd0df3
commit
6bb5037eae
10 changed files with 27 additions and 10 deletions
|
|
@ -11,4 +11,16 @@ export class FetchError extends LibError{
|
|||
: 'Fetching data failed',
|
||||
cause);
|
||||
}
|
||||
}
|
||||
|
||||
export class BatchExecutionError extends LibError{
|
||||
constructor(cause?: unknown){
|
||||
super('Batched execution failed.', cause);
|
||||
}
|
||||
}
|
||||
|
||||
export class HTTPError extends LibError{
|
||||
constructor(errorCode: number, cause?: unknown){
|
||||
super(`Received HTTP error code: ${errorCode}`, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ import { getDbEnv } from '../db/client'
|
|||
import { subscribedThemeparks, attractionSubscriptions } from "../db/schema";
|
||||
import { SubscribedThemeparks } from "../types/subscribed-themeparks";
|
||||
import { AttractionSubscription } from "../types/attraction-subscriptions";
|
||||
import { KVParseError, SendNotificationError } from "../errors/background-error";
|
||||
import { KVParseError, SendNotificationError } from "../errors";
|
||||
import httpRequest from "../lib/http-request";
|
||||
import fetchAttractions from "../lib/fetch-attractions";
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { attraction, themepark } from '../db/schema'
|
|||
import { inArray } from 'drizzle-orm'
|
||||
import { Attraction } from '../types/attraction'
|
||||
import { ThemeparkSelect } from '../types/themepark'
|
||||
import { AttractionImportError, BackgroundDatabaseError } from '../errors/background-error'
|
||||
import { AttractionImportError, BackgroundDatabaseError } from '../errors'
|
||||
import asyncBatchJob from '../lib/async-batch-job'
|
||||
import fetchAttractions from '../lib/fetch-attractions'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { getDbEnv } from '../db/client'
|
||||
import { themepark } from '../db/schema'
|
||||
import { countryCodesDE } from '../lib/countries'
|
||||
import { BackgroundFetchError, ThemeparkUpdateError } from '../errors/background-error'
|
||||
import { FetchError, ThemeparkUpdateError } from '../errors'
|
||||
import httpRequest from '../lib/http-request'
|
||||
import asyncBatchJob from '../lib/async-batch-job'
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ async function fetchThemeparks(
|
|||
return result;
|
||||
}
|
||||
catch(e){
|
||||
throw new BackgroundFetchError(e);
|
||||
throw new FetchError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { BatchExecutionError } from "../errors";
|
||||
|
||||
/**
|
||||
* Run any async operation in (multiple) batches
|
||||
* @param data Array to split into batches
|
||||
|
|
@ -12,6 +14,6 @@ export default async function asyncBatchJob<T>(data: T[], batchSize: number = 20
|
|||
}
|
||||
}
|
||||
catch(e){
|
||||
throw new Error(`Batch execution failed: ${e}`);
|
||||
throw new BatchExecutionError(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { AttractionImport } from '../types/attraction'
|
||||
import httpRequest from '../lib/http-request'
|
||||
import { FetchError } from '../errors';
|
||||
|
||||
/**
|
||||
* Fetching the attractions from a specified park
|
||||
|
|
@ -25,6 +26,6 @@ export default async function fetchAttractions(
|
|||
return result;
|
||||
}
|
||||
catch(e){
|
||||
throw new Error(`Failed to fetch attractions: ${e}`);
|
||||
throw new FetchError(e, endpoint);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import { HTTPError } from "../errors";
|
||||
|
||||
/**
|
||||
* Executes a HTTP Request with option for custom header & body parameters
|
||||
* @param endpoint Request endpoint
|
||||
|
|
@ -26,7 +28,7 @@ export default async function httpRequest<TResponse, TBody = undefined>(
|
|||
|
||||
|
||||
if (!response.ok){
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
throw new HTTPError(response.status);
|
||||
}
|
||||
|
||||
if(response.status === 204){
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { UserSelect } from "../types/user";
|
|||
import { user } from "../db/schema";
|
||||
import { like } from "drizzle-orm";
|
||||
import { DrizzleD1Database } from "drizzle-orm/d1";
|
||||
import { MissingMailError, UserInactiveError, DatabaseError } from "../errors/http-error";
|
||||
import { MissingMailError, UserInactiveError, DatabaseError } from "../errors";
|
||||
|
||||
/**
|
||||
* Returns the details of a user from the given context
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Hono, Context } from 'hono'
|
|||
import { getDbContext } from '../db/client'
|
||||
import { attractionNotification, notificationMethod } from '../db/schema'
|
||||
import { and, eq } from 'drizzle-orm'
|
||||
import { DatabaseError, InvalidParameter, MissingParameter } from '../errors/http-error'
|
||||
import { DatabaseError, InvalidParameter, MissingParameter } from '../errors'
|
||||
import { getUser } from '../lib/user-auth'
|
||||
import { Message } from '../types/response'
|
||||
import { NotificationMethodSelect } from '../types/notification-method'
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { getDbContext } from '../db/client'
|
|||
import { themepark, attraction } from '../db/schema'
|
||||
import { responseCache } from '../lib/cache'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { DatabaseError } from '../errors/http-error'
|
||||
import { DatabaseError } from '../errors'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue