@dasch-swiss/dsp-js
Version:
TypeScript client library for DSP-API
69 lines • 1.91 kB
JavaScript
import { ApiResponse } from './api-response';
/**
* @category Response
*/
export class ApiResponseError extends ApiResponse {
// </editor-fold>
/// //////////////
// CONSTRUCTOR //
/// //////////////
// <editor-fold desc="">
/**
* Constructor.
*/
constructor() {
super();
/// ////////////
// CONSTANTS //
/// ////////////
// <editor-fold desc="">
// </editor-fold>
/// /////////////
// PROPERTIES //
/// /////////////
// <editor-fold desc="">
/**
* Detailed error, if applicable
*/
this.error = '';
}
// </editor-fold>
/// //////////
// METHODS //
/// //////////
// <editor-fold desc="">
/**
* Create an instance from an AjaxError.
*/
static fromAjaxError(ajaxError) {
// check if the error is already a ApiResponseError
if (ajaxError instanceof ApiResponseError) {
return ajaxError;
}
const 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
*/
static fromErrorString(error, responseData) {
const response = new ApiResponseError();
response.method = responseData.method;
response.url = responseData.url;
response.status = responseData.status;
response.error = error;
return response;
}
}
//# sourceMappingURL=api-response-error.js.map