Skip to content

Commit 8a0f481

Browse files
authored
Merge pull request #516 from ZIMkaRU/bugfix/fix-currency-conversion-data-finding-error
Fix currency conversion data finding error
2 parents 691eb64 + 43cce70 commit 8a0f481

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

workers/loc.api/errors/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class ObjectMappingError extends BaseError {
7171
}
7272

7373
class CurrencyConversionDataFindingError extends BaseError {
74-
constructor (message = 'ERR_DATA_IS_NOT_FOUND_TO_CONVERT_CURRENCY') {
75-
super(message)
74+
constructor (data, message = 'ERR_DATA_IS_NOT_FOUND_TO_CONVERT_CURRENCY') {
75+
super({ data, message })
7676
}
7777
}
7878

workers/loc.api/sync/currency.converter/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,25 @@ class CurrencyConverter {
348348
if (typeof symbol !== 'string') {
349349
return ''
350350
}
351-
if (symbol.length < 8) {
351+
if (symbol.length < 6) {
352352
return symbol
353353
}
354+
355+
const hasFlag = (
356+
symbol.startsWith('t') ||
357+
symbol.startsWith('f')
358+
)
359+
const flag = hasFlag
360+
? symbol[0]
361+
: 't'
362+
354363
if (
355-
symbol[0] !== 't' &&
356-
symbol[0] !== 'f'
364+
symbol.length === 7 &&
365+
hasFlag
357366
) {
358367
return symbol
359368
}
360369

361-
const flag = symbol[0]
362370
const [firstSymb, lastSymb] = splitSymbolPairs(symbol)
363371
const _firstSymb = this._getConvertingSymb(firstSymb)
364372
const _lastSymb = this._getConvertingSymb(lastSymb)
@@ -1031,7 +1039,9 @@ class CurrencyConverter {
10311039
)
10321040

10331041
if (!Number.isFinite(price)) {
1034-
throw new CurrencyConversionDataFindingError()
1042+
throw new CurrencyConversionDataFindingError(
1043+
{ symbol: reqSymb, mts }
1044+
)
10351045
}
10361046

10371047
return price
@@ -1082,7 +1092,9 @@ class CurrencyConverter {
10821092
)
10831093
}
10841094

1085-
throw new CurrencyConversionDataFindingError()
1095+
throw new CurrencyConversionDataFindingError(
1096+
{ symbol: reqSymb, mts: end }
1097+
)
10861098
}
10871099

10881100
async convertManyByCandles (data, convSchema) {

0 commit comments

Comments
 (0)