UNPKG

@itwin/clash-detection-client

Version:

Clash Detection client for the iTwin platform

64 lines 3.01 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import axios from "axios"; import { ClashDetectionErrorParser } from "../ClashDetectionErrorParser"; /** Default implementation for {@link RestClient} interface that uses `axios` library for sending the requests. */ export class AxiosRestClient { constructor(parseErrorFunc = ClashDetectionErrorParser.parse) { this._parseErrorFunc = parseErrorFunc; } async sendGetRequest(params) { const requestConfig = { headers: params.headers, }; return axios.get(params.url, requestConfig) .then((successResponse) => this.handleSuccess(successResponse)) .catch((errorResponse) => this.handleError(errorResponse)); } async sendPostRequest(params) { var _a; const requestConfig = { headers: params.headers, }; return axios.post(params.url, (_a = params.body) !== null && _a !== void 0 ? _a : {}, requestConfig) .then((successResponse) => this.handleSuccess(successResponse)) .catch((errorResponse) => this.handleError(errorResponse)); } async sendPutRequest(params) { var _a; const requestConfig = { headers: params.headers, }; return axios.put(params.url, (_a = params.body) !== null && _a !== void 0 ? _a : {}, requestConfig) .then((successResponse) => this.handleSuccess(successResponse)) .catch((errorResponse) => this.handleError(errorResponse)); } async sendPatchRequest(params) { var _a; const requestConfig = { headers: params.headers, }; return axios.patch(params.url, (_a = params.body) !== null && _a !== void 0 ? _a : {}, requestConfig) .then((successResponse) => this.handleSuccess(successResponse)) .catch((errorResponse) => this.handleError(errorResponse)); } async sendDeleteRequest(params) { const requestConfig = { headers: params.headers, }; return axios.delete(params.url, requestConfig) .then((successResponse) => this.handleSuccess(successResponse)) .catch((errorResponse) => this.handleError(errorResponse)); } // eslint-disable-next-line @typescript-eslint/no-explicit-any handleError(errorResponse) { var _a, _b; return Promise.reject(this._parseErrorFunc({ statusCode: (_a = errorResponse.response) === null || _a === void 0 ? void 0 : _a.status, body: (_b = errorResponse.response) === null || _b === void 0 ? void 0 : _b.data })); } handleSuccess(response) { return response.data; } } //# sourceMappingURL=AxiosRestClient.js.map