@@ -127,6 +127,16 @@ public final class APITestCommand: Command {
127127        ) 
128128        . flatMap  {  trackProgress ( testProgressTracker? . markBuilding ( ) )  } 
129129        . flatMap  {  openAPIDoc ( on:  eventLoop,  from:  source)  } 
130+         . flatMapError  {  error in 
131+             let  errorString :  String 
132+             if  let  error =  error as?  Abort  { 
133+                 errorString =  " HTTP Error:  \( error. status. code)  -  \( error. status. reasonPhrase) " 
134+             }  else  { 
135+                 errorString =  OpenAPI . Error ( from:  error) . localizedDescription
136+             } 
137+             testLogger. error ( path:  nil ,  context:  " Prepping/Retrieving OpenAPI Source " ,  message:  errorString) 
138+             return  eventLoop. makeFailedFuture ( error) 
139+         } 
130140        . flatMap  {  openAPIDoc in 
131141            produceAPITestPackage ( 
132142                on:  eventLoop, 
@@ -149,10 +159,6 @@ public final class APITestCommand: Command {
149159            requestLogger? . info ( " Cleaning up tests in  \( outPath) " ) 
150160        } 
151161        . recover  {  error in 
152-             // For requests with the ability to distinguish between request
153-             // logging and test logging, only log this "summary" message
154-             // to the request logger. For any other request, log it to the
155-             // test logger.
156162            if  let  requestLogger =  requestLogger { 
157163                requestLogger. error ( " Testing Failed " , 
158164                                     metadata:  [ " error " :  . stringConvertible( String ( describing:  error) ) ] ) 
@@ -251,7 +257,12 @@ public func openAPIDoc(
251257            return  loop. makeFailedFuture ( Abort ( . badRequest) ) 
252258        } 
253259
254-         return  client. execute ( request:  request) . flatMapThrowing  {  response in 
260+         return  client. execute ( request:  request) . flatMap  {  ( response)  ->  EventLoopFuture < HTTPClient . Response >  in 
261+             guard  response. status ==  . ok else  { 
262+                 return  loop. makeFailedFuture ( Abort ( response. status) ) 
263+             } 
264+             return  loop. makeSucceededFuture ( response) 
265+         } . flatMapThrowing  {  response in 
255266            return  try ClientResponse ( status:  response. status,  headers:  response. headers,  body:  response. body) 
256267                . content. decode ( OpenAPI . Document. self) 
257268        } . always  {  _ in  try ! . syncShutdown ( )  } 
0 commit comments