All files / lib swsLastErrors.js

64.29% Statements 9/14
25% Branches 1/4
50% Functions 2/4
64.29% Lines 9/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40              1x 1x 1x         1x       1x         1x                 1x 1x         1x  
/**
 * Created by sv2 on 2/18/17.
 * Last Errors
 */
 
'use strict';
 
var util = require('util');
var debug = require('debug')('sws:lasterrors');
var swsUtil = require('./swsUtil');
 
function swsLastErrors() {
 
    // Store Last 100 errors
    this.last_errors = [];
 
}
 
swsLastErrors.prototype.getStats = function() {
    return this.last_errors;
};
 
// Add information about last error
swsLastErrors.prototype.addError = function(rrr) {
    this.last_errors.push(rrr);
    // Clean up if more than allowed
    if (this.last_errors.length > 100) {
        this.last_errors.shift();
    }
};
 
// Check if this qualifies as longest request, and store is yes
swsLastErrors.prototype.processReqResData = function(rrr) {
    Iif(swsUtil.isError(rrr.http.response.code)){
        this.addError(rrr);
    }
};
 
module.exports = swsLastErrors;