UNPKG

trainingpeaks-sdk

Version:
96 lines (95 loc) 3.84 kB
import { ERROR_CODES } from './index.js'; export class WorkoutNotFoundError extends Error { constructor(workoutId) { super(`Workout with ID '${workoutId}' not found`); this.name = 'WorkoutNotFoundError'; this.code = ERROR_CODES.WORKOUT_NOT_FOUND; this.statusCode = 404; Object.setPrototypeOf(this, WorkoutNotFoundError.prototype); } } export class WorkoutValidationError extends Error { constructor(message, details) { super(message); this.name = 'WorkoutValidationError'; this.code = ERROR_CODES.WORKOUT_VALIDATION_FAILED; this.statusCode = 400; this.details = details; Object.setPrototypeOf(this, WorkoutValidationError.prototype); } } export class WorkoutOperationNotAllowedError extends Error { constructor(operation, reason) { super(`Operation '${operation}' is not allowed: ${reason}`); this.name = 'WorkoutOperationNotAllowedError'; this.code = ERROR_CODES.WORKOUT_REPOSITORY_ERROR; this.statusCode = 403; Object.setPrototypeOf(this, WorkoutOperationNotAllowedError.prototype); } } export class WorkoutUploadError extends Error { constructor(message, fileInfo) { super(message); this.name = 'WorkoutUploadError'; this.code = ERROR_CODES.WORKOUT_UPLOAD_FAILED; this.statusCode = 500; this.fileInfo = fileInfo; Object.setPrototypeOf(this, WorkoutUploadError.prototype); } } export class WorkoutFileProcessingError extends Error { constructor(message, fileType) { super(message); this.name = 'WorkoutFileProcessingError'; this.code = ERROR_CODES.WORKOUT_FILE_INVALID; this.statusCode = 400; this.fileType = fileType; Object.setPrototypeOf(this, WorkoutFileProcessingError.prototype); } } export class WorkoutStructureError extends Error { constructor(message, structureDetails) { super(message); this.name = 'WorkoutStructureError'; this.code = ERROR_CODES.WORKOUT_STRUCTURE_INVALID; this.statusCode = 400; this.structureDetails = structureDetails; Object.setPrototypeOf(this, WorkoutStructureError.prototype); } } export class WorkoutServiceUnavailableError extends Error { constructor(serviceName, reason) { super(`Workout service '${serviceName}' is unavailable: ${reason}`); this.name = 'WorkoutServiceUnavailableError'; this.code = ERROR_CODES.WORKOUT_REPOSITORY_ERROR; this.statusCode = 503; Object.setPrototypeOf(this, WorkoutServiceUnavailableError.prototype); } } export class WorkoutDataCorruptionError extends Error { constructor(workoutId, corruptionType) { super(`Workout data for ID '${workoutId}' is corrupted: ${corruptionType}`); this.name = 'WorkoutDataCorruptionError'; this.code = ERROR_CODES.WORKOUT_REPOSITORY_ERROR; this.statusCode = 500; Object.setPrototypeOf(this, WorkoutDataCorruptionError.prototype); } } export class WorkoutQuotaExceededError extends Error { constructor(quotaType, limit, current) { super(`Workout quota exceeded for '${quotaType}': ${current}/${limit}`); this.name = 'WorkoutQuotaExceededError'; this.code = ERROR_CODES.WORKOUT_REPOSITORY_ERROR; this.statusCode = 429; Object.setPrototypeOf(this, WorkoutQuotaExceededError.prototype); } } export class WorkoutSyncError extends Error { constructor(workoutId, syncDirection, reason) { super(`Workout sync failed for ID '${workoutId}' (${syncDirection}): ${reason}`); this.name = 'WorkoutSyncError'; this.code = ERROR_CODES.WORKOUT_REPOSITORY_ERROR; this.statusCode = 500; Object.setPrototypeOf(this, WorkoutSyncError.prototype); } }