mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix fs use & error handling (#1777)
* fix fs use * Release 3.1.3-next.0 * update error handling * Release 3.1.3-next.1
This commit is contained in:
parent
b599093901
commit
38cc02849e
16
CHANGELOG.md
16
CHANGELOG.md
@ -4,8 +4,23 @@ All notable changes to this project will be documented in this file. Dates are d
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
#### [v3.1.3-next.1](https://github.com/oceanprotocol/ocean.js/compare/v3.1.3-next.0...v3.1.3-next.1)
|
||||
|
||||
- update error handling [`aada8e9`](https://github.com/oceanprotocol/ocean.js/commit/aada8e92af9273ccc20e86dc00ea73bcb7e8dfdf)
|
||||
|
||||
#### [v3.1.3-next.0](https://github.com/oceanprotocol/ocean.js/compare/v3.1.2...v3.1.3-next.0)
|
||||
|
||||
> 6 October 2023
|
||||
|
||||
- Bump @types/crypto-js from 4.1.1 to 4.1.2 [`#1774`](https://github.com/oceanprotocol/ocean.js/pull/1774)
|
||||
- Bump @types/chai-spies from 1.0.3 to 1.0.4 [`#1776`](https://github.com/oceanprotocol/ocean.js/pull/1776)
|
||||
- fix fs use [`735dc2f`](https://github.com/oceanprotocol/ocean.js/commit/735dc2f62b976be683bc9fcd7f8940e715b18519)
|
||||
- Release 3.1.3-next.0 [`5ac5d1f`](https://github.com/oceanprotocol/ocean.js/commit/5ac5d1f44a637b5d8d285757941b0393bb3a7983)
|
||||
|
||||
#### [v3.1.2](https://github.com/oceanprotocol/ocean.js/compare/v3.1.1...v3.1.2)
|
||||
|
||||
> 25 September 2023
|
||||
|
||||
- Feature/ Use custom addresses & fallback signature to legacy [`#1772`](https://github.com/oceanprotocol/ocean.js/pull/1772)
|
||||
- Bump typedoc from 0.24.8 to 0.25.1 [`#1770`](https://github.com/oceanprotocol/ocean.js/pull/1770)
|
||||
- Bump cross-fetch from 3.1.5 to 4.0.0 [`#1764`](https://github.com/oceanprotocol/ocean.js/pull/1764)
|
||||
@ -13,6 +28,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
- optimize disk space [`#1771`](https://github.com/oceanprotocol/ocean.js/pull/1771)
|
||||
- Added gen-x-testnet to ConfigHelper [`#1741`](https://github.com/oceanprotocol/ocean.js/pull/1741)
|
||||
- Remove custom contracts [`#1769`](https://github.com/oceanprotocol/ocean.js/pull/1769)
|
||||
- Release 3.1.2 [`a157154`](https://github.com/oceanprotocol/ocean.js/commit/a157154f857f363ddabc77298a9377070972153a)
|
||||
|
||||
#### [v3.1.1](https://github.com/oceanprotocol/ocean.js/compare/v3.1.0...v3.1.1)
|
||||
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@oceanprotocol/lib",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3-next.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@oceanprotocol/lib",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3-next.1",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "^1.1.14",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@oceanprotocol/lib",
|
||||
"source": "./src/index.ts",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3-next.1",
|
||||
"description": "JavaScript client library for Ocean Protocol",
|
||||
"main": "./dist/lib.js",
|
||||
"umd:main": "dist/lib.umd.js",
|
||||
|
@ -1,6 +1,5 @@
|
||||
// eslint-disable-next-line import/no-named-default
|
||||
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
|
||||
import fs from 'fs'
|
||||
import { Config } from '.'
|
||||
import { LoggerInstance } from '../utils'
|
||||
|
||||
@ -180,8 +179,8 @@ export class ConfigHelper {
|
||||
DFRewards,
|
||||
DFStrategyV1,
|
||||
veFeeEstimate,
|
||||
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }),
|
||||
...(process.env.PROVIDER_URI && { providerUri: process.env.PROVIDER_URI })
|
||||
...(process.env.AQUARIUS_URL && { metadataCacheUri: process.env.AQUARIUS_URL }),
|
||||
...(process.env.PROVIDER_URL && { providerUri: process.env.PROVIDER_URL })
|
||||
}
|
||||
} else {
|
||||
// no custom addresses structure was passed, trying to load default
|
||||
@ -219,8 +218,8 @@ export class ConfigHelper {
|
||||
DFRewards,
|
||||
DFStrategyV1,
|
||||
veFeeEstimate,
|
||||
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }),
|
||||
...(process.env.PROVIDER_URI && { providerUri: process.env.PROVIDER_URI })
|
||||
...(process.env.AQUARIUS_URL && { metadataCacheUri: process.env.AQUARIUS_URL }),
|
||||
...(process.env.PROVIDER_URL && { providerUri: process.env.PROVIDER_URL })
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -241,16 +240,14 @@ export class ConfigHelper {
|
||||
LoggerInstance.error(`No config found for given network '${network}'`)
|
||||
return null
|
||||
}
|
||||
const customAddresses = process.env.ADDRESS_FILE
|
||||
? JSON.parse(
|
||||
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
||||
fs.readFileSync(process.env.ADDRESS_FILE, 'utf8')
|
||||
)
|
||||
: null
|
||||
const contractAddressesConfig = this.getAddressesFromEnv(
|
||||
config.network,
|
||||
customAddresses
|
||||
)
|
||||
|
||||
let addresses
|
||||
try {
|
||||
addresses = JSON.parse(process.env.ADDRESS_FILE)
|
||||
} catch (e) {
|
||||
addresses = null
|
||||
}
|
||||
const contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses)
|
||||
config = { ...config, ...contractAddressesConfig }
|
||||
|
||||
const nodeUri = infuraProjectId
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { LoggerInstance } from './Logger'
|
||||
|
||||
const PREDEFINED_ERRORS = {
|
||||
datasets: {
|
||||
invalid: 'Datasets is not a list, as expected'
|
||||
@ -74,17 +76,23 @@ const PREDEFINED_ERRORS = {
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: Object): string {
|
||||
const key = Object.keys(error)[0]
|
||||
if (key === 'error') {
|
||||
const message = error[key]
|
||||
const errorMessage =
|
||||
PREDEFINED_ERRORS[key][message] || `Provider request failed: ${message}`
|
||||
return errorMessage
|
||||
} else {
|
||||
const errorObject = error[key]
|
||||
const messagekey = Object.keys(error)[1]
|
||||
const errorMessage = error[messagekey]
|
||||
return `${errorMessage} : ${errorObject}`
|
||||
export function getErrorMessage(err: string): string {
|
||||
try {
|
||||
const error = JSON.parse(err)
|
||||
const key = Object.keys(error)[0]
|
||||
if (key === 'error') {
|
||||
const message = error[key]
|
||||
const errorMessage =
|
||||
PREDEFINED_ERRORS[key][message] || `Provider request failed: ${message}`
|
||||
return errorMessage
|
||||
} else {
|
||||
const errorObject = error[key]
|
||||
const messagekey = Object.keys(error)[1]
|
||||
const errorMessage = error[messagekey]
|
||||
return `${errorMessage} : ${errorObject}`
|
||||
}
|
||||
} catch (e) {
|
||||
LoggerInstance.error('[getErrorMessage] error: ', e)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user