Skip to content

Commit

Permalink
added error AirportNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Dec 23, 2023
1 parent fe78e9d commit 5c33083
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
9 changes: 7 additions & 2 deletions nodejs/FlightRadar24/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const APIRequest = require("./request");
const Airport = require("./entities/airport");
const Flight = require("./entities/flight");
const FlightTrackerConfig = require("./flightTrackerConfig");
const {LoginError} = require("./errors");
const {AirportNotFoundError, LoginError} = require("./errors");
const {isNumeric} = require("./util");


Expand Down Expand Up @@ -80,7 +80,12 @@ class FlightRadar24API {
const response = new APIRequest(Core.airportDataUrl.replace("{}", code), null, Core.jsonHeaders);
await response.receive();

return new Airport({}, (await response.getContent())["details"]);
const details = (await response.getContent())["details"];

if (details === undefined) {
throw new AirportNotFoundError("Could not find an airport by the code '" + code + "'.");
}
return new Airport({}, details);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions nodejs/FlightRadar24/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class LoginError extends Error {
class AirportNotFoundError extends Error {
constructor(message) {
super(message);

Expand All @@ -19,4 +19,14 @@ class CloudflareError extends Error {
}
}

module.exports = {LoginError, CloudflareError};
class LoginError extends Error {
constructor(message) {
super(message);

this.name = this.constructor.name;

Error.captureStackTrace(this, this.constructor);
}
}

module.exports = {AirportNotFoundError, CloudflareError, LoginError};
4 changes: 2 additions & 2 deletions nodejs/FlightRadar24/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* https://www.flightradar24.com/terms-and-conditions
*/

const {CloudflareError, LoginError} = require("./errors");
const {AirportNotFoundError, CloudflareError, LoginError} = require("./errors");
const FlightRadar24API = require("./api");
const FlightTrackerConfig = require("./flightTrackerConfig");
const Airport = require("./entities/airport");
Expand All @@ -24,6 +24,6 @@ module.exports = {
FlightRadar24API,
FlightTrackerConfig,
Airport, Entity, Flight,
CloudflareError, LoginError,
AirportNotFoundError, CloudflareError, LoginError,
author, version,
};
1 change: 0 additions & 1 deletion nodejs/FlightRadar24/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ function isNumeric(text) {
return true;
}


module.exports = {isNumeric};

0 comments on commit 5c33083

Please sign in to comment.