| 1 | import Redis from 'ioredis'; |
| 2 | |
| 3 | import { RedisService } |
| 4 | import { HttpException, HttpStatus |
| 5 | import { ConfigService } |
| 6 | |
| 7 | export interface FlightAwareAirport |
| 8 | code: string |
| 9 | code_icao?: string |
| 10 | code_iata?: string |
| 11 | code_lid?: string |
| 12 | timezone?: string |
| 13 | name?: string |
| 14 | city?: string |
| 15 | airport_info_url?: string |
| 16 | } |
| 17 | |
| 18 | export interface FlightAwareAircraft |
| 19 | fa_flight_id: string; |
| 20 | ident: string; |
| 21 | ident_icao?: string |
| 22 | ident_iata?: string |
| 23 | actual_runway_off?: string |
| 24 | actual_runway_on?: string |
| 25 | operator?: string |
| 26 | operator_icao?: string |
| 27 | operator_iata?: string |
| 28 | flight_number?: string |
| 29 | registration?: string |
| 30 | atc_ident?: string |
| 31 | inbound_fa_flight_id?: string |
| 32 | codeshares?: string |
| 33 | codeshares_iata?: string |
| 34 | blocked?: boolean |
| 35 | diverted?: boolean |
| 36 | cancelled?: boolean |
| 37 | position_only?: boolean |
| 38 | origin: FlightAwareAirport |
| 39 | destination?: FlightAwareAirport |
| 40 | departure_delay?: number |
| 41 | arrival_delay?: number |
| 42 | filed_ete?: number |
| 43 | progress_percent?: number |
| 44 | status: string; |
| 45 | aircraft_type?: string |
| 46 | route_distance?: number |
| 47 | filed_airspeed?: number |
| 48 | filed_altitude?: number |
| 49 | route?: string |
| 50 | baggage_claim?: string |
| 51 | seats_cabin_business?: number |
| 52 | seats_cabin_coach?: number |
| 53 | seats_cabin_first?: number |
| 54 | gate_origin?: string |
| 55 | gate_destination?: string |
| 56 | terminal_origin?: string |
| 57 | terminal_destination?: string |
| 58 | type: 'General_Aviation |
| 59 | scheduled_out?: string |
| 60 | estimated_out?: string |
| 61 | actual_out?: string |
| 62 | scheduled_off?: string |
| 63 | estimated_off?: string |
| 64 | actual_off?: string |
| 65 | scheduled_on?: string |
| 66 | estimated_on?: string |
| 67 | actual_on?: string |
| 68 | scheduled_in?: string |
| 69 | estimated_in?: string |
| 70 | actual_in?: string |
| 71 | foresight_predictions_available?: boolean |
| 72 | aircraft_type_faa?: string |
| 73 | aircraft_family?: string |
| 74 | manufacturer?: string |
| 75 | model?: string |
| 76 | engine_type?: string |
| 77 | engine_count?: string |
| 78 | wake_turbulence_category?: string |
| 79 | flight_plan?: { |
| 80 | flight_plan_id: string |
| 81 | aircraft_id: string |
| 82 | aircraft_type: string |
| 83 | aircraft_faa?: string |
| 84 | aircraft_short?: string |
| 85 | owner?: string |
| 86 | owner_icao?: string |
| 87 | owner_iata?: string |
| 88 | owner_name?: string |
| 89 | manufacturer?: string |
| 90 | model?: string |
| 91 | priority?: string |
| 92 | filed_ete?: string |
| 93 | filed_departure_time?: string |
| 94 | estimated_departure_time?: string |
| 95 | filed_arrival_time?: string |
| 96 | estimated_arrival_time?: string |
| 97 | filed_airspeed_kts?: number |
| 98 | filed_airspeed_mach?: string |
| 99 | route_distance?: number |
| 100 | filed_altitude?: number |
| 101 | route?: string |
| 102 | actual_departure_time?: string |
| 103 | actual_arrival_time?: string |
| 104 | diverted?: string |
| 105 | origin: { |
| 106 | code: string |
| 107 | code_icao?: string |
| 108 | code_iata?: string |
| 109 | code_lid?: string |
| 110 | timezone: string |
| 111 | name: string |
| 112 | city?: string |
| 113 | airport_info_url?: string |
| 114 | }; |
| 115 | destination?: { |
| 116 | code: string |
| 117 | code_icao?: string |
| 118 | code_iata?: string |
| 119 | code_lid?: string |
| 120 | timezone: string |
| 121 | name: string |
| 122 | city?: string |
| 123 | airport_info_url?: string |
| 124 | }; |
| 125 | waypoints?: Array |
| 126 | ident: string |
| 127 | name?: string |
| 128 | lat: number |
| 129 | lon: number |
| 130 | altitude?: number |
| 131 | alt_desc?: string |
| 132 | type?: string |
| 133 | }>; |
| 134 | }; |
| 135 | origin_position?: { |
| 136 | fa_flight_id: string |
| 137 | altitude: number |
| 138 | altitude_change?: string |
| 139 | groundspeed: number |
| 140 | heading: number |
| 141 | latitude: number |
| 142 | longitude: number |
| 143 | timestamp: string |
| 144 | update_type?: string |
| 145 | }; |
| 146 | destination_position?: { |
| 147 | fa_flight_id: string |
| 148 | altitude: number |
| 149 | altitude_change?: string |
| 150 | groundspeed: number |
| 151 | heading: number |
| 152 | latitude: number |
| 153 | longitude: number |
| 154 | timestamp: string |
| 155 | update_type?: string |
| 156 | }; |
| 157 | waypoints?: Array |
| 158 | fa_flight_id: string |
| 159 | altitude: number |
| 160 | altitude_change?: string |
| 161 | groundspeed: number |
| 162 | heading: number |
| 163 | latitude: number |
| 164 | longitude: number |
| 165 | timestamp: string |
| 166 | update_type?: string |
| 167 | }>; |
| 168 | last_position?: { |
| 169 | fa_flight_id: string |
| 170 | altitude: number |
| 171 | altitude_change?: string |
| 172 | groundspeed: number |
| 173 | heading: number |
| 174 | latitude: number |
| 175 | longitude: number |
| 176 | timestamp: string |
| 177 | update_type?: string |
| 178 | }; |
| 179 | bounding_box?: { |
| 180 | fa_flight_id: string |
| 181 | num_positions: number |
| 182 | start_time: string |
| 183 | end_time: string |
| 184 | min_latitude: number |
| 185 | max_latitude: number |
| 186 | min_longitude: number |
| 187 | max_longitude: number |
| 188 | }; |
| 189 | has_forecast?: boolean |
| 190 | estimated_runway_arrival?: string |
| 191 | estimated_runway_departure?: string |
| 192 | actual_runway_arrival?: string |
| 193 | actual_runway_departure?: string |
| 194 | } |
| 195 | |
| 196 | export interface FlightAwareResponse |
| 197 | flights: FlightAwareAircraft |
| 198 | links: { |
| 199 | next?: string |
| 200 | prev?: string |
| 201 | }; |
| 202 | num_pages: number; |
| 203 | } |
| 204 | |
| 205 | @Injectable() |
| 206 | export class FlightAwareService |
| 207 | private readonly baseUrl |
| 208 | private readonly cacheTTL |
| 209 | private readonly maxRequestsPerMinute |
| 210 | private readonly rateLimitWindow |
| 211 | private redis: |
| 212 | |
| 213 | constructor( |
| 214 | private readonly redisService |
| 215 | private readonly configService |
| 216 | ) { |
| 217 | this.redis = |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Check and enforce rate limiting (10 requests per minute) |
| 222 | */ |
| 223 | private async checkRateLimit |
| 224 | const rateLimitKey = |
| 225 | const now = |
| 226 | |
| 227 | try { |
| 228 | // Get current request timestamps |
| 229 | const requestTimes = |
| 230 | const currentTime = |
| 231 | |
| 232 | // Filter out requests older than 1 minute |
| 233 | const recentRequests = |
| 234 | .map(time => |
| 235 | .filter(time => |
| 236 | |
| 237 | // Check if we're at the limit |
| 238 | if (recentRequests.length |
| 239 | const oldestRequest = |
| 240 | const waitTime = |
| 241 | |
| 242 | console.warn(`FlightAware: Rate limit reached ( |
| 243 | |
| 244 | // Wait for the oldest request to expire |
| 245 | await new Promise |
| 246 | } |
| 247 | |
| 248 | // Add current request timestamp |
| 249 | await this.redis |
| 250 | await this.redis |
| 251 | |
| 252 | console.log(`FlightAware: Rate limit check passed ( |
| 253 | } catch (error) |
| 254 | console.warn('FlightAware: Rate limit check failed, proceeding anyway: |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Get flights within a bounding box using FlightAware's search API |
| 260 | */ |
| 261 | async getFlightsInBounds( |
| 262 | minLat: number, |
| 263 | maxLat: number, |
| 264 | minLng: number, |
| 265 | maxLng: number, |
| 266 | ): Promise<FlightAwareResponse |
| 267 | const cacheKey = |
| 268 | |
| 269 | // Check cache first |
| 270 | try { |
| 271 | const cached = |
| 272 | if (cached) { |
| 273 | const cachedData = |
| 274 | console.log('FlightAware: Returning cached data |
| 275 | |
| 276 | // Return in the same format as the API response |
| 277 | return { |
| 278 | flights: cachedData.flights |
| 279 | links: cachedData.links |
| 280 | num_pages: cachedData.num_pages |
| 281 | }; |
| 282 | } |
| 283 | } catch (error) |
| 284 | console.warn('Redis cache read error: |
| 285 | } |
| 286 | |
| 287 | const apiKey = |
| 288 | if (!apiKey) |
| 289 | throw new HttpException( |
| 290 | 'FlightAware API key not configured', |
| 291 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 292 | ); |
| 293 | } |
| 294 | |
| 295 | try { |
| 296 | // Check rate limit before making API call |
| 297 | await this.checkRateLimit |
| 298 | |
| 299 | // Build query for bounding box search using FlightAware CLI format |
| 300 | const query = |
| 301 | |
| 302 | const url = |
| 303 | url.searchParams.append |
| 304 | url.searchParams.append |
| 305 | |
| 306 | const response = |
| 307 | headers: { |
| 308 | 'x-apikey': apiKey, |
| 309 | Accept: 'application/json; charset=UTF-8', |
| 310 | }, |
| 311 | }); |
| 312 | |
| 313 | if (!response.ok |
| 314 | // Log error response |
| 315 | const contentType = |
| 316 | let errorBody; |
| 317 | |
| 318 | try { |
| 319 | if (contentType && |
| 320 | errorBody = await |
| 321 | } else { |
| 322 | errorBody = await |
| 323 | } |
| 324 | |
| 325 | console.error('FlightAware API Error Response: |
| 326 | status: response.status |
| 327 | statusText: response.statusText |
| 328 | contentType, |
| 329 | body: errorBody, |
| 330 | url: url.toString |
| 331 | }); |
| 332 | } catch (logError) |
| 333 | console.error('Failed to log FlightAware error response: |
| 334 | } |
| 335 | |
| 336 | if (response.status |
| 337 | throw new HttpException( |
| 338 | 'FlightAware API authentication failed', |
| 339 | HttpStatus.UNAUTHORIZED, |
| 340 | ); |
| 341 | } |
| 342 | if (response.status |
| 343 | throw new HttpException( |
| 344 | 'FlightAware API rate limit exceeded', |
| 345 | HttpStatus.TOO_MANY_REQUESTS, |
| 346 | ); |
| 347 | } |
| 348 | throw new HttpException( |
| 349 | `FlightAware API request failed with status ${response.status |
| 350 | HttpStatus.BAD_GATEWAY, |
| 351 | ); |
| 352 | } |
| 353 | |
| 354 | let data = |
| 355 | let allFlights = |
| 356 | let nextUrl = |
| 357 | |
| 358 | // Follow pagination links to get all flights |
| 359 | while (nextUrl) { |
| 360 | try { |
| 361 | console.log(`FlightAware: Fetching next page: |
| 362 | |
| 363 | // Check rate limit before each pagination request |
| 364 | await this.checkRateLimit |
| 365 | |
| 366 | const nextResponse = |
| 367 | headers: { |
| 368 | 'x-apikey': apiKey, |
| 369 | Accept: 'application/json; charset=UTF-8', |
| 370 | }, |
| 371 | }); |
| 372 | |
| 373 | if (!nextResponse.ok |
| 374 | console.warn(`FlightAware: Failed to fetch next page ( |
| 375 | break; |
| 376 | } |
| 377 | |
| 378 | const nextData = |
| 379 | allFlights = allFlights. |
| 380 | nextUrl = nextData. |
| 381 | |
| 382 | console.log(`FlightAware: Fetched |
| 383 | } catch (paginationError) |
| 384 | console.error('FlightAware: Error fetching next page: |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // Create final response with all flights |
| 390 | const finalData = |
| 391 | ...data, |
| 392 | flights: allFlights |
| 393 | }; |
| 394 | |
| 395 | // Cache both the processed data and raw API response |
| 396 | try { |
| 397 | const processedData = |
| 398 | flights: allFlights, |
| 399 | links: data.links |
| 400 | num_pages: data.num_pages |
| 401 | cached_at: new Date |
| 402 | query: query, |
| 403 | bounds: { minLat, |
| 404 | total_flights_fetched: allFlights.length |
| 405 | }; |
| 406 | |
| 407 | // Cache the processed data (what we return) |
| 408 | await this.redis |
| 409 | |
| 410 | // Cache the raw API response for analysis |
| 411 | const rawCacheKey = |
| 412 | await this.redis |
| 413 | |
| 414 | console.log(`FlightAware: Fetched |
| 415 | } catch (error) |
| 416 | console.warn('Redis cache write error: |
| 417 | } |
| 418 | |
| 419 | return finalData; |
| 420 | } catch (error) |
| 421 | console.error('FlightAware API error: |
| 422 | if (error instanceof |
| 423 | throw error; |
| 424 | } |
| 425 | throw new HttpException( |
| 426 | 'Failed to fetch flight data from FlightAware', |
| 427 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 428 | ); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Search flights by ident (returns array of flights) |
| 434 | */ |
| 435 | async searchFlightsByIdent(ident |
| 436 | const cacheKey = |
| 437 | |
| 438 | // Check cache first |
| 439 | try { |
| 440 | const cached = |
| 441 | if (cached) { |
| 442 | console.log(`FlightAware: Returning cached search data for |
| 443 | return JSON.parse |
| 444 | } |
| 445 | } catch (error) |
| 446 | console.warn('Redis cache read error: |
| 447 | } |
| 448 | |
| 449 | const apiKey = |
| 450 | if (!apiKey) |
| 451 | throw new HttpException( |
| 452 | 'FlightAware API key not configured', |
| 453 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 454 | ); |
| 455 | } |
| 456 | |
| 457 | try { |
| 458 | // Check rate limit before making API call |
| 459 | await this.checkRateLimit |
| 460 | |
| 461 | const url = |
| 462 | |
| 463 | const response = |
| 464 | headers: { |
| 465 | 'x-apikey': apiKey, |
| 466 | Accept: 'application/json; charset=UTF-8', |
| 467 | }, |
| 468 | }); |
| 469 | |
| 470 | if (!response.ok |
| 471 | // Log error response |
| 472 | const contentType = |
| 473 | let errorBody; |
| 474 | |
| 475 | try { |
| 476 | if (contentType && |
| 477 | errorBody = await |
| 478 | } else { |
| 479 | errorBody = await |
| 480 | } |
| 481 | |
| 482 | console.error('FlightAware API Error Response: |
| 483 | status: response.status |
| 484 | statusText: response.statusText |
| 485 | contentType, |
| 486 | body: errorBody, |
| 487 | url: url.toString |
| 488 | ident, |
| 489 | }); |
| 490 | } catch (logError) |
| 491 | console.error('Failed to log FlightAware error response: |
| 492 | } |
| 493 | |
| 494 | if (response.status |
| 495 | return null; |
| 496 | } |
| 497 | if (response.status |
| 498 | throw new HttpException( |
| 499 | 'FlightAware API authentication failed', |
| 500 | HttpStatus.UNAUTHORIZED, |
| 501 | ); |
| 502 | } |
| 503 | throw new HttpException( |
| 504 | `FlightAware API request failed with status ${response.status |
| 505 | HttpStatus.BAD_GATEWAY, |
| 506 | ); |
| 507 | } |
| 508 | |
| 509 | const data = |
| 510 | |
| 511 | // Cache both the processed data and raw API response |
| 512 | try { |
| 513 | const processedData = |
| 514 | ...data, |
| 515 | cached_at: new Date |
| 516 | ident: ident |
| 517 | }; |
| 518 | |
| 519 | // Cache the processed data (what we return) |
| 520 | await this.redis |
| 521 | |
| 522 | // Cache the raw API response for analysis |
| 523 | const rawCacheKey = |
| 524 | await this.redis |
| 525 | |
| 526 | console.log( |
| 527 | `FlightAware: Search data for ${ident} cached for 10 seconds (processed + raw)` |
| 528 | ); |
| 529 | } catch (error) |
| 530 | console.warn('Redis cache write error: |
| 531 | } |
| 532 | |
| 533 | return data; |
| 534 | } catch (error) |
| 535 | console.error('FlightAware API error: |
| 536 | if (error instanceof |
| 537 | throw error; |
| 538 | } |
| 539 | throw new HttpException( |
| 540 | 'Failed to fetch flight data from FlightAware', |
| 541 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 542 | ); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Get flight track data (positions) by fa_flight_id |
| 548 | * Note: This method caches at the FlightAware service level. |
| 549 | * The application layer (flight.service.ts) has its own 30s cache. |
| 550 | */ |
| 551 | async getFlightTrack(faFlightId |
| 552 | const cacheKey = |
| 553 | const trackCacheTTL = |
| 554 | |
| 555 | // Check cache first |
| 556 | try { |
| 557 | const cached = |
| 558 | if (cached) { |
| 559 | console.log(`FlightAware: Returning cached track data for |
| 560 | return JSON.parse |
| 561 | } |
| 562 | } catch (error) |
| 563 | console.warn('Redis cache read error: |
| 564 | } |
| 565 | |
| 566 | const apiKey = |
| 567 | if (!apiKey) |
| 568 | throw new HttpException( |
| 569 | 'FlightAware API key not configured', |
| 570 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 571 | ); |
| 572 | } |
| 573 | |
| 574 | try { |
| 575 | // Check rate limit before making API call |
| 576 | await this.checkRateLimit |
| 577 | |
| 578 | const url = |
| 579 | |
| 580 | const response = |
| 581 | headers: { |
| 582 | 'x-apikey': apiKey, |
| 583 | Accept: 'application/json; charset=UTF-8', |
| 584 | }, |
| 585 | }); |
| 586 | |
| 587 | if (!response.ok |
| 588 | // Log error response |
| 589 | const contentType = |
| 590 | let errorBody; |
| 591 | |
| 592 | try { |
| 593 | if (contentType && |
| 594 | errorBody = await |
| 595 | } else { |
| 596 | errorBody = await |
| 597 | } |
| 598 | |
| 599 | console.error('FlightAware API Error Response: |
| 600 | status: response.status |
| 601 | statusText: response.statusText |
| 602 | contentType, |
| 603 | body: errorBody, |
| 604 | url: url.toString |
| 605 | faFlightId, |
| 606 | }); |
| 607 | } catch (logError) |
| 608 | console.error('Failed to log FlightAware error response: |
| 609 | } |
| 610 | |
| 611 | if (response.status |
| 612 | throw new HttpException( |
| 613 | 'Flight track not found', |
| 614 | HttpStatus.NOT_FOUND, |
| 615 | ); |
| 616 | } |
| 617 | if (response.status |
| 618 | throw new HttpException( |
| 619 | 'FlightAware API authentication failed', |
| 620 | HttpStatus.UNAUTHORIZED, |
| 621 | ); |
| 622 | } |
| 623 | throw new HttpException( |
| 624 | `FlightAware API request failed with status ${response.status |
| 625 | HttpStatus.BAD_GATEWAY, |
| 626 | ); |
| 627 | } |
| 628 | |
| 629 | const data = |
| 630 | |
| 631 | // Cache the data for 30 seconds |
| 632 | try { |
| 633 | const processedData = |
| 634 | ...data, |
| 635 | cached_at: new Date |
| 636 | fa_flight_id: faFlightId |
| 637 | }; |
| 638 | |
| 639 | await this.redis |
| 640 | |
| 641 | console.log( |
| 642 | `FlightAware: Track data for ${faFlightId} cached for ${ |
| 643 | ); |
| 644 | } catch (error) |
| 645 | console.warn('Redis cache write error: |
| 646 | } |
| 647 | |
| 648 | return data; |
| 649 | } catch (error) |
| 650 | console.error('FlightAware API error: |
| 651 | if (error instanceof |
| 652 | throw error; |
| 653 | } |
| 654 | throw new HttpException( |
| 655 | 'Failed to fetch flight track data from FlightAware', |
| 656 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 657 | ); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Get a specific flight by ident |
| 663 | */ |
| 664 | async getFlightByIdent(ident |
| 665 | const cacheKey = |
| 666 | |
| 667 | // Check cache first |
| 668 | try { |
| 669 | const cached = |
| 670 | if (cached) { |
| 671 | console.log(`FlightAware: Returning cached flight data for |
| 672 | return JSON.parse |
| 673 | } |
| 674 | } catch (error) |
| 675 | console.warn('Redis cache read error: |
| 676 | } |
| 677 | |
| 678 | const apiKey = |
| 679 | if (!apiKey) |
| 680 | throw new HttpException( |
| 681 | 'FlightAware API key not configured', |
| 682 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 683 | ); |
| 684 | } |
| 685 | |
| 686 | try { |
| 687 | // Check rate limit before making API call |
| 688 | await this.checkRateLimit |
| 689 | |
| 690 | const url = |
| 691 | |
| 692 | const response = |
| 693 | headers: { |
| 694 | 'x-apikey': apiKey, |
| 695 | Accept: 'application/json; charset=UTF-8', |
| 696 | }, |
| 697 | }); |
| 698 | |
| 699 | if (!response.ok |
| 700 | // Log error response |
| 701 | const contentType = |
| 702 | let errorBody; |
| 703 | |
| 704 | try { |
| 705 | if (contentType && |
| 706 | errorBody = await |
| 707 | } else { |
| 708 | errorBody = await |
| 709 | } |
| 710 | |
| 711 | console.error('FlightAware API Error Response: |
| 712 | status: response.status |
| 713 | statusText: response.statusText |
| 714 | contentType, |
| 715 | body: errorBody, |
| 716 | url: url.toString |
| 717 | ident, |
| 718 | }); |
| 719 | } catch (logError) |
| 720 | console.error('Failed to log FlightAware error response: |
| 721 | } |
| 722 | |
| 723 | if (response.status |
| 724 | return null; |
| 725 | } |
| 726 | if (response.status |
| 727 | throw new HttpException( |
| 728 | 'FlightAware API authentication failed', |
| 729 | HttpStatus.UNAUTHORIZED, |
| 730 | ); |
| 731 | } |
| 732 | throw new HttpException( |
| 733 | `FlightAware API request failed with status ${response.status |
| 734 | HttpStatus.BAD_GATEWAY, |
| 735 | ); |
| 736 | } |
| 737 | |
| 738 | const data = |
| 739 | |
| 740 | // Cache both the processed data and raw API response |
| 741 | try { |
| 742 | const processedData = |
| 743 | ...data, |
| 744 | cached_at: new Date |
| 745 | ident: ident |
| 746 | }; |
| 747 | |
| 748 | // Cache the processed data (what we return) |
| 749 | await this.redis |
| 750 | |
| 751 | // Cache the raw API response for analysis |
| 752 | const rawCacheKey = |
| 753 | await this.redis |
| 754 | |
| 755 | console.log( |
| 756 | `FlightAware: Flight data for ${ident} cached for 10 seconds (processed + raw)` |
| 757 | ); |
| 758 | } catch (error) |
| 759 | console.warn('Redis cache write error: |
| 760 | } |
| 761 | |
| 762 | return data; |
| 763 | } catch (error) |
| 764 | console.error('FlightAware API error: |
| 765 | if (error instanceof |
| 766 | throw error; |
| 767 | } |
| 768 | throw new HttpException( |
| 769 | 'Failed to fetch flight data from FlightAware', |
| 770 | HttpStatus.INTERNAL_SERVER_ERROR, |
| 771 | ); |
| 772 | } |
| 773 | } |
| 774 | } |