UNPKG

@knora/api

Version:

JavaScript library that handles API requests to Knora

67 lines 2.66 kB
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; 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 api_response_1 = require("./api-response"); var api_response_error_1 = require("./api-response-error"); var data_error_1 = require("./data-error"); 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 = api_response_error_1.ApiResponseError.fromErrorString(error, responseData); throw new data_error_1.DataError(error, responseError); } } return responseData; }; return ApiResponseData; }(api_response_1.ApiResponse)); exports.ApiResponseData = ApiResponseData; //# sourceMappingURL=api-response-data.js.map