"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var lwm2m_error_1 = require("../error/lwm2m-error");
var result_code_translation_1 = require("./result-code-translation");
var method_type_1 = require("../request/method-type");
exports.TapResponseErrorCode = "TapResponseError";
var ResponseError = /** @class */ (function (_super) {
    __extends(ResponseError, _super);
    function ResponseError(response, request) {
        var _this = _super.call(this, ResponseError.createErrorMessage(response, request)) || this;
        _this.response = response;
        _this.request = request;
        _this.code = exports.TapResponseErrorCode;
        return _this;
    }
    ResponseError.createErrorMessage = function (response, request) {
        var codeRet = response.codeRet();
        var msg = 'Tap request failed. ';
        if (request) {
            msg = "Tap request " + (method_type_1.MethodType[request.getMethod()] + " " + request.getHeader().getPath()) + " failed. ";
        }
        var errorExplained = (codeRet in result_code_translation_1.ResultCodeTranslation ? result_code_translation_1.ResultCodeTranslation[codeRet] : "an unknown error");
        msg += errorExplained + " (code=0x" + codeRet.toString(16) + ")";
        return msg;
    };
    return ResponseError;
}(lwm2m_error_1.LWM2MError));
exports.ResponseError = ResponseError;
