Skip to content

Commit

Permalink
fix: change function request name and use it in ovh provider
Browse files Browse the repository at this point in the history
  • Loading branch information
vafanassieff committed May 28, 2022
1 parent 6baa272 commit 43ad9bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
14 changes: 3 additions & 11 deletions src/providers/ovh.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
)

Expand Down

0 comments on commit 43ad9bf

Please sign in to comment.