Browse Source

fix: issue with NaN error code responses

Karol Sójko 3 years ago
parent
commit
2cb470b99e

+ 4 - 1
packages/api-gateway/src/Controller/AuthMiddleware.ts

@@ -99,7 +99,10 @@ export class AuthMiddleware extends BaseMiddleware {
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
       }
       }
 
 
-      const errorCode = (error as AxiosError).isAxiosError ? +((error as AxiosError).code as string) : 500
+      const errorCode =
+        (error as AxiosError).isAxiosError && !isNaN(+((error as AxiosError).code as string))
+          ? +((error as AxiosError).code as string)
+          : 500
 
 
       response.status(errorCode).send(errorMessage)
       response.status(errorCode).send(errorMessage)
 
 

+ 4 - 1
packages/api-gateway/src/Controller/SubscriptionTokenAuthMiddleware.ts

@@ -88,7 +88,10 @@ export class SubscriptionTokenAuthMiddleware extends BaseMiddleware {
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
       }
       }
 
 
-      const errorCode = (error as AxiosError).isAxiosError ? +((error as AxiosError).code as string) : 500
+      const errorCode =
+        (error as AxiosError).isAxiosError && !isNaN(+((error as AxiosError).code as string))
+          ? +((error as AxiosError).code as string)
+          : 500
 
 
       response.status(errorCode).send(errorMessage)
       response.status(errorCode).send(errorMessage)
 
 

+ 4 - 1
packages/api-gateway/src/Service/Http/HttpService.ts

@@ -133,7 +133,10 @@ export class HttpService implements HttpServiceInterface {
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
         response.setHeader('content-type', (error as AxiosError).response?.headers['content-type'] as string)
       }
       }
 
 
-      const errorCode = (error as AxiosError).isAxiosError ? +((error as AxiosError).code as string) : 500
+      const errorCode =
+        (error as AxiosError).isAxiosError && !isNaN(+((error as AxiosError).code as string))
+          ? +((error as AxiosError).code as string)
+          : 500
 
 
       response.status(errorCode).send(errorMessage)
       response.status(errorCode).send(errorMessage)
     }
     }