@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
88 lines • 2.89 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { ApiResponse } from "./api-response";
/**
* @category Response
*/
var ApiResponseError = /** @class */ (function (_super) {
__extends(ApiResponseError, _super);
// </editor-fold>
/////////////////
// CONSTRUCTOR //
/////////////////
// <editor-fold desc="">
/**
* Constructor.
*/
function ApiResponseError() {
var _this = _super.call(this) || this;
///////////////
// CONSTANTS //
///////////////
// <editor-fold desc="">
// </editor-fold>
////////////////
// PROPERTIES //
////////////////
// <editor-fold desc="">
/**
* Detailed error, if applicable
*/
_this.error = "";
return _this;
}
// </editor-fold>
/////////////
// METHODS //
/////////////
// <editor-fold desc="">
/**
* Create an instance from an AjaxError.
*/
ApiResponseError.fromAjaxError = function (ajaxError) {
// check if the error is already a ApiResponseError
if (ajaxError instanceof ApiResponseError) {
return ajaxError;
}
var response = new ApiResponseError();
if (ajaxError.request) {
if (ajaxError.request.method)
response.method = ajaxError.request.method;
if (ajaxError.request.url)
response.url = ajaxError.request.url;
}
if (ajaxError.xhr)
response.status = ajaxError.xhr.status;
response.error = ajaxError;
return response;
};
/**
* Create an instance from an error string.
* @param responseData
* @param error
*/
ApiResponseError.fromErrorString = function (error, responseData) {
var response = new ApiResponseError();
response.method = responseData.method;
response.url = responseData.url;
response.status = responseData.status;
response.error = error;
return response;
};
return ApiResponseError;
}(ApiResponse));
export { ApiResponseError };
//# sourceMappingURL=api-response-error.js.map