UNPKG

straydog-js

Version:

Drop-in API monitoring for any Node.js backend

30 lines (29 loc) 994 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExpressResponseHandler = void 0; const response_model_1 = require("../../config/data/response.model"); class ExpressResponseHandler { constructor(res, err, latency, requestId) { this.response = res; this.responseModel = new response_model_1.ResponseModel('response'); this.latency = latency; this.requestId = requestId; this.error = err; } save() { const data = { latency: this.latency, end_time: (new Date()).toISOString(), status_code: this.response.statusCode, request_id: this.requestId, error: null, error_stack: null }; if (this.error) { data.error = this.error.message; data.error_stack = this.error.stack; } return this.responseModel.insert(data); } } exports.ExpressResponseHandler = ExpressResponseHandler;