File tree Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,9 @@ const fetchAllLogs = async (req, res) => {
67
67
prev : prevUrl ,
68
68
} ) ;
69
69
} catch ( err ) {
70
+ if ( err . statusCode ) {
71
+ return res . status ( err . statusCode ) . json ( { error : err . message } ) ;
72
+ }
70
73
logger . error ( ERROR_WHILE_FETCHING_LOGS , err ) ;
71
74
return res . boom . badImplementation ( ERROR_WHILE_FETCHING_LOGS ) ;
72
75
}
Original file line number Diff line number Diff line change @@ -188,7 +188,9 @@ const fetchAllLogs = async (query) => {
188
188
endDate = endDate ? parseInt ( endDate ) : null ;
189
189
190
190
if ( startDate && endDate && startDate > endDate ) {
191
- throw new Error ( "Start date cannot be greater than end date." ) ;
191
+ const error = new Error ( "Start date cannot be greater than end date." ) ;
192
+ error . statusCode = 400 ;
193
+ throw error ;
192
194
}
193
195
194
196
const buildTimestamp = ( date ) => ( {
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ describe("/logs", function () {
241
241
. get ( `/logs?username=${ username } &startDate=${ startDate } &endDate=${ endDate } &dev=true` )
242
242
. set ( "cookie" , `${ cookieName } =${ superUserToken } ` )
243
243
. end ( function ( _err , res ) {
244
- expect ( res ) . to . have . status ( 500 ) ;
244
+ expect ( res ) . to . have . status ( 400 ) ;
245
245
expect ( res . body . error ) . to . equal ( "Start date cannot be greater than end date." ) ;
246
246
return done ( ) ;
247
247
} ) ;
You can’t perform that action at this time.
0 commit comments