Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CORE) Add error code and catch error #1132

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"adapter-hash": "node --no-warnings --import=specifier-resolution-node/register --experimental-json-modules dist/cli/generate-adapter-hash.js",
"aggregator-hash": "node --no-warnings --import=specifier-resolution-node/register --experimental-json-modules dist/cli/generate-aggregator-hash.js",
"flush": "node --no-warnings --import=specifier-resolution-node/register --experimental-json-modules dist/tools/flush-queues.js",
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
"test": "node --no-warnings --experimental-vm-modules node_modules/.bin/jest",
"lint": "DEBUG=eslint:cli-engine eslint 'src/**/*.ts' 'src/*.ts' 'test/*.ts'",
"bull-dashboard": "docker-compose -f docker-compose.bull-monitor.yaml up"
},
Expand Down
20 changes: 16 additions & 4 deletions core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export async function getReporters({
return (await axios.get(endpoint, { data: { service, chain } }))?.data
} catch (e) {
logger?.error({ name: 'getReporters', file: FILE_NAME, ...e }, 'error')
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
if (e.code === 'ECONNREFUSED') {
throw new OraklError(OraklErrorCode.FailedToConnectAPI)
} else {
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
}
}
}

Expand All @@ -92,8 +96,12 @@ export async function getReporter({
const endpoint = buildUrl(ORAKL_NETWORK_API_URL, `reporter/${id}`)
return (await axios.get(endpoint))?.data
} catch (e) {
logger?.error({ name: 'getReporter', file: FILE_NAME, ...e }, 'error')
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
logger?.error({ name: 'getReporters', file: FILE_NAME, ...e }, 'error')
if (e.code === 'ECONNREFUSED') {
throw new OraklError(OraklErrorCode.FailedToConnectAPI)
} else {
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
}
}
}

Expand Down Expand Up @@ -131,7 +139,11 @@ export async function getReporterByOracleAddress({
return reporter[0]
} catch (e) {
logger.error({ name: 'getReportersByOracleAddress', file: FILE_NAME, ...e }, 'error')
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
if (e.code === 'ECONNREFUSED') {
throw new OraklError(OraklErrorCode.FailedToConnectAPI)
} else {
throw new OraklError(OraklErrorCode.GetReporterRequestFailed)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ export enum OraklErrorCode {
AxiosBadRequest,
AxiosCanceledByUser,
AxiosNotSupported,
AxiosInvalidUrl
AxiosInvalidUrl,
FailedToConnectAPI
}
Loading