import { FetchError } from 'ofetch'; import { TwitterError } from '../../models/errors/TwitterError'; import { IErrorHandler } from '../../types/ErrorHandler'; import { IErrorData as IRawErrorData, IErrorDetails as IRawErrorDetails } from '../../types/raw/base/Error'; /** * The base service that handles any errors. * * @public */ export class ErrorService implements IErrorHandler { /** * Handles errors thrown by Twitter. * * @param error - The error response received from Twitter. */ private _handleFetchError(error: FetchError): void { throw new TwitterError(error); } /** * Handle unknown error. */ private _handleUnknownError(error: unknown): void { throw error; } /** * The method called when an error response is received from Twitter API. * * @param error - The error caught while making HTTP request to Twitter API. */ public handle(error: unknown): void { if (error instanceof FetchError) { this._handleFetchError(error as FetchError); } else { this._handleUnknownError(error); } } }