All files / core/dist transformData.js

100% Statements 22/22
75% Branches 9/12
100% Functions 2/2
100% Lines 17/17

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55  9x 9x 9x 9x 9x   7x 7x 7x 7x 4x     3x   7x 7x                                         9x 9x         1x                 9x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resourceTransform = exports.httpTransform = void 0;
var common_1 = require("@mito/common");
var utils_1 = require("@mito/utils");
var errorId_1 = require("./errorId");
function httpTransform(data) {
    var message = '';
    var elapsedTime = data.elapsedTime, time = data.time, method = data.method, traceId = data.traceId, type = data.type, status = data.status;
    var name = type + "--" + method;
    if (status === 0) {
        message = elapsedTime <= common_1.globalVar.crossOriginThreshold ? 'http请求失败,失败原因:跨域限制或域名不存在' : 'http请求失败,失败原因:超时';
    }
    else {
        message = utils_1.fromHttpStatus(status);
    }
    message = message === utils_1.SpanStatus.Ok ? message : message + " " + errorId_1.getRealPath(data.url);
    return {
        type: common_1.ERRORTYPES.FETCH_ERROR,
        url: utils_1.getLocationHref(),
        time: time,
        elapsedTime: elapsedTime,
        level: utils_1.Severity.Low,
        message: message,
        name: name,
        request: {
            httpType: type,
            traceId: traceId,
            method: method,
            url: data.url,
            data: data.reqData || ''
        },
        response: {
            status: status,
            data: data.responseText
        }
    };
}
exports.httpTransform = httpTransform;
var resourceMap = {
    img: '图片',
    script: 'js脚本'
};
function resourceTransform(target) {
    return {
        type: common_1.ERRORTYPES.RESOURCE_ERROR,
        url: utils_1.getLocationHref(),
        message: '资源地址: ' + (target.src.slice(0, 100) || target.href.slice(0, 100)),
        level: utils_1.Severity.Low,
        time: utils_1.getTimestamp(),
        name: (resourceMap[target.localName] || target.localName) + "\u52A0\u8F7D\u5931\u8D25"
    };
}
exports.resourceTransform = resourceTransform;
//# sourceMappingURL=transformData.js.map