Skip to content

Commit

Permalink
Check if properRoute is found before acting on it
Browse files Browse the repository at this point in the history
In the cases where the request route is not matched to any Koa route,
bail out before trying to format the path string.

Issue: PayU#59
  • Loading branch information
kdhira committed Feb 21, 2022
1 parent b9ab859 commit 3d4c631
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/koa-middleware.js
Expand Up @@ -33,7 +33,7 @@ class KoaMiddleware {
}
}

_handleResponse (ctx) {
_handleResponse(ctx) {
const responseLength = parseInt(ctx.response.get('Content-Length')) || 0;

const route = this._getRoute(ctx) || 'N/A';
Expand Down Expand Up @@ -93,6 +93,12 @@ class KoaMiddleware {
}
});

// If proper route is not found, send an undefined route
// The caller is responsible for setting a default "N/A" route in this case
if (!properRoute) {
return undefined;
}

let route = properRoute.path;
route = route.endsWith('/') ? route.substring(0, route.length - 1) : route;
return route;
Expand Down

0 comments on commit 3d4c631

Please sign in to comment.