22
33const express = require ( "express" )
44const v1 = express . Router ( )
5+ const error = { error : "No Matches Found" }
56
67// Get most recent launch
78v1 . get ( "/latest" , ( req , res ) => {
@@ -22,7 +23,7 @@ v1.get("/", (req, res) => {
2223 global . db . collection ( "launch" ) . find ( { "launch_year" : `${ year } ` } , { "_id" : 0 } ) . sort ( { "flight_number" : - 1 } )
2324 . toArray ( ( err , doc ) => {
2425 if ( doc . length == 0 ) {
25- res . end ( "No Matches Found" )
26+ res . end ( JSON . stringify ( error , null , 2 ) )
2627 }
2728 res . end ( JSON . stringify ( doc , null , 2 ) )
2829 } )
@@ -31,7 +32,7 @@ v1.get("/", (req, res) => {
3132 . sort ( { "flight_number" : 1 } )
3233 . toArray ( ( err , doc ) => {
3334 if ( doc . length == 0 ) {
34- res . end ( "No Matches Found" )
35+ res . end ( JSON . stringify ( error , null , 2 ) )
3536 }
3637 res . end ( JSON . stringify ( doc , null , 2 ) )
3738 } )
@@ -40,7 +41,7 @@ v1.get("/", (req, res) => {
4041 . sort ( { "flight_number" : 1 } )
4142 . toArray ( ( err , doc ) => {
4243 if ( doc . length == 0 ) {
43- res . end ( "No Matches Found" )
44+ res . end ( JSON . stringify ( error , null , 2 ) )
4445 }
4546 res . end ( JSON . stringify ( doc , null , 2 ) )
4647 } )
@@ -60,7 +61,7 @@ v1.get("/cores/:core", (req, res) => {
6061 . toArray ( ( err , doc ) => {
6162 if ( err ) return console . log ( err )
6263 if ( doc . length == 0 ) {
63- res . end ( "No Matches Found" )
64+ res . end ( JSON . stringify ( error , null , 2 ) )
6465 }
6566 res . end ( JSON . stringify ( doc , null , 2 ) )
6667 } )
@@ -73,7 +74,7 @@ v1.get("/caps/:cap", (req, res) => {
7374 . toArray ( ( err , doc ) => {
7475 if ( err ) return console . log ( err )
7576 if ( doc . length == 0 ) {
76- res . end ( "No Matches Found" )
77+ res . end ( JSON . stringify ( error , null , 2 ) )
7778 }
7879 res . end ( JSON . stringify ( doc , null , 2 ) )
7980 } )
0 commit comments