@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
70 lines • 2.72 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";
import { ApiResponseError } from "./api-response-error";
import { DataError } from "./data-error";
/**
* @category Response
*/
var ApiResponseData = /** @class */ (function (_super) {
__extends(ApiResponseData, _super);
// </editor-fold>
/////////////////
// CONSTRUCTOR //
/////////////////
// <editor-fold desc="">
/**
* Constructor.
*/
function ApiResponseData() {
return _super.call(this) || this;
}
// </editor-fold>
/////////////
// METHODS //
/////////////
// <editor-fold desc="">
/**
* Create an instance from an AjaxResponse.
* If the return type in the body shall be checked, this method requires the arguments dataType and jsonConvert.
* @throws DataError
*/
ApiResponseData.fromAjaxResponse = function (ajaxResponse, dataType, jsonConvert) {
var responseData = new ApiResponseData();
responseData.response = ajaxResponse;
if (ajaxResponse.request && ajaxResponse.request.method)
responseData.method = ajaxResponse.request.method;
if (ajaxResponse.request && ajaxResponse.request.url)
responseData.url = ajaxResponse.request.url;
if (ajaxResponse.xhr)
responseData.status = ajaxResponse.xhr.status;
// Apply json2typescript if required
responseData.body = ajaxResponse.response;
if (dataType && jsonConvert) {
try {
responseData.body = jsonConvert.deserializeObject(ajaxResponse.response, dataType);
}
catch (error) {
var responseError = ApiResponseError.fromErrorString(error, responseData);
throw new DataError(error, responseError);
}
}
return responseData;
};
return ApiResponseData;
}(ApiResponse));
export { ApiResponseData };
//# sourceMappingURL=api-response-data.js.map