-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1216 from navikt/put-utfyltsoknad-metrics
Prom metrics express.json and verify idporten token
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/fyllut-backend/src/middleware/expressJsonMetricHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import { appMetrics } from '../services'; | ||
|
||
const expressJsonMetricHandler = (fn: Function) => async (req: Request, res: Response, next: NextFunction) => { | ||
if (req.method === 'PUT' && req.url.includes('/send-inn/utfyltsoknad')) { | ||
const stopTimer = appMetrics.expressJsonBodyParserDuration.startTimer({ endpoint: 'put-utfyltsoknad' }); | ||
let errorOccured = false; | ||
try { | ||
await fn(req, res, next); | ||
} catch (err) { | ||
errorOccured = true; | ||
throw err; | ||
} finally { | ||
stopTimer({ error: String(errorOccured) }); | ||
} | ||
} else { | ||
await fn(req, res, next); | ||
} | ||
}; | ||
|
||
export default expressJsonMetricHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters