flight-planner
Version:
Plan and route VFR flights
63 lines (62 loc) • 1.92 kB
JavaScript
/**
* Base class for all flight planner exceptions.
*/
export class FlightPlannerError extends Error {
code;
constructor(message, code) {
super(message);
this.code = code;
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
/**
* Exception thrown when insufficient waypoints are provided for route planning.
* A valid route requires at least a departure and arrival waypoint.
*/
export class InsufficientWaypointsError extends FlightPlannerError {
constructor(providedCount = 0) {
const message = `At least departure and arrival waypoints are required. Provided: ${providedCount} waypoint(s)`;
super(message, 'INSUFFICIENT_WAYPOINTS');
}
}
/**
* Exception thrown when route parsing fails.
*/
export class RouteParsingError extends FlightPlannerError {
routeString;
constructor(message, routeString) {
super(message, 'ROUTE_PARSING_ERROR');
this.routeString = routeString;
}
}
/**
* Exception thrown when aircraft data is invalid or missing.
*/
export class AircraftDataError extends FlightPlannerError {
aircraftRegistration;
constructor(message, aircraftRegistration) {
super(message, 'AIRCRAFT_DATA_ERROR');
this.aircraftRegistration = aircraftRegistration;
}
}
/**
* Exception thrown when waypoint data is invalid or missing.
*/
export class WaypointDataError extends FlightPlannerError {
waypointIdentifier;
constructor(message, waypointIdentifier) {
super(message, 'WAYPOINT_DATA_ERROR');
this.waypointIdentifier = waypointIdentifier;
}
}
/**
* Exception thrown when weather data cannot be retrieved or is invalid.
*/
export class WeatherDataError extends FlightPlannerError {
location;
constructor(message, location) {
super(message, 'WEATHER_DATA_ERROR');
this.location = location;
}
}