From 43ad9bf9b5bbb26c0d4c3b6c5dbb2d620f30631f Mon Sep 17 00:00:00 2001 From: Victor Afanassieff Date: Sat, 28 May 2022 23:53:35 +0200 Subject: [PATCH] fix: change function request name and use it in ovh provider --- src/providers/ovh.js | 14 +++----------- src/utils.js | 2 +- src/versions.js | 4 ++-- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/providers/ovh.js b/src/providers/ovh.js index 3b0abcd..c9b4d47 100644 --- a/src/providers/ovh.js +++ b/src/providers/ovh.js @@ -1,5 +1,7 @@ import { createHash } from 'node:crypto' +import { httpRequest } from '#src/utils.js' + const endpoints = { 'ovh-eu': 'eu.api.ovh.com', 'ovh-us': 'api.us.ovhcloud.com', @@ -43,17 +45,7 @@ const request = async (path, method, parameters, config) => { .digest('hex'), } - const response = await fetch(url, options) - - if (response.ok) { - return response.json() - } else { - const data = await response.json() - - const error = data.message ? new Error(data.message) : new Error(data) - - throw error - } + return httpRequest(url, options) } /** diff --git a/src/utils.js b/src/utils.js index f76eb5d..eee93b4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -71,7 +71,7 @@ export const getProviders = async () => { * @param {object} options Fetch options * @returns {Promise} Result of the fetch */ -export const request = async (url, options) => { +export const httpRequest = async (url, options) => { const response = await fetch(url, options) if (response.ok) { diff --git a/src/versions.js b/src/versions.js index d05f974..0f35655 100644 --- a/src/versions.js +++ b/src/versions.js @@ -3,7 +3,7 @@ import fs from 'node:fs/promises' import path from 'node:path' import { URL } from 'node:url' -import { request } from '#src/utils.js' +import { httpRequest } from '#src/utils.js' /** * @typedef {object} Versions @@ -17,7 +17,7 @@ import { request } from '#src/utils.js' * @returns {Versions} latest abd current version */ export default async () => { - const { latest } = await request( + const { latest } = await httpRequest( 'https://registry.npmjs.org/-/package/@vafanassieff/email-alias/dist-tags' )