UNPKG

@ui5/task-adaptation

Version:

Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment

36 lines 1.2 kB
import axios from "axios"; import ServerError from "../model/serverError.js"; export default class RequestUtil { static async head(url) { return this.request(url, axios.head); } static async get(url, options) { return this.request(url, axios.get, options).then(response => response.data); } static async request(url, method, options) { try { return await method(url, options); } catch (error) { this.handleError(error, url); } } static handleError(error, uri) { if (error.response) { // HTTP Status Code > 2xx if (error.response.status >= 500) { throw new ServerError(uri, error); } else { throw new Error(`Unexpected response received from '${uri}': ${error.response.status} ${error.response.data ?? ""}`); } } else if (error.request) { throw new Error(`No response was received from '${uri}': ${error.code}`); } else { throw new Error(`Error sending request to '${uri}': ${error.code}`); } } } //# sourceMappingURL=requestUtil.js.map