Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
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
1 change: 0 additions & 1 deletion src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const unrecoverableErrors = [
'CustomLimitsReached',
'OfferingsValidationError',
'InvalidCurrency',
'ContractBuyValidationError',
'NotDefaultCurrency',
'PleaseAuthenticate',
'FinancialAssessmentRequired',
Expand Down
36 changes: 22 additions & 14 deletions src/botPage/bot/TradeEngine/Proposal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { translate } from '../../../common/i18n';
import { tradeOptionToProposal, doUntilDone } from '../tools';
import { proposalsReady, clearProposals } from './state/actions';
import { TrackJSError } from '../../view/logger';

export default Engine =>
class Proposal extends Engine {
Expand All @@ -22,15 +23,20 @@ export default Engine =>
this.data.get('proposals').forEach(proposal => {
if (proposal.contractType === contractType) {
if (proposal.error) {
throw Error(proposal.error.error.error.message);
const { error } = proposal.error;
throw new TrackJSError(error.error.code, error.error.message, error);
} else {
toBuy = proposal;
}
}
});

if (!toBuy) {
throw Error(translate('Selected proposal does not exist'));
throw new TrackJSError(
'CustomInvalidProposal',
translate('Selected proposal does not exist'),
Array.from(this.data.get('proposals')).map(proposal => proposal[1])
);
}

return {
Expand All @@ -46,14 +52,12 @@ export default Engine =>
this.store.dispatch(clearProposals());
}
requestProposals() {
this.proposalTemplates.map(proposal =>
doUntilDone(() =>
this.api
.subscribeToPriceForContractProposal(proposal)
// eslint-disable-next-line consistent-return
.catch(e => {
Promise.all(
this.proposalTemplates.map(proposal =>
doUntilDone(() =>
this.api.subscribeToPriceForContractProposal(proposal).catch(e => {
if (e && e.name === 'RateLimit') {
return Promise.reject(e);
throw e;
}

const errorCode = e.error && e.error.error && e.error.error.code;
Expand All @@ -62,18 +66,22 @@ export default Engine =>
const { uuid } = e.error.echo_req.passthrough;

if (!this.data.hasIn(['forgetProposals', uuid])) {
// Add to proposals map with error. Will later be shown to user, see selectProposal.
this.data = this.data.setIn(['proposals', uuid], {
...proposal,
contractType: proposal.contract_type,
error : e,
...proposal.passthrough,
error: e,
});
}
} else {
this.$scope.observer.emit('Error', e);

return null;
}

throw e;
})
)
)
);
).catch(e => this.$scope.observer.emit('Error', e));
}
observeProposals() {
this.listen('proposal', r => {
Expand Down
29 changes: 23 additions & 6 deletions src/botPage/bot/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,29 @@ const getBackoffDelay = (error, delayIndex) => {
return linearIncrease * 1000;
};

export const shouldThrowError = (e, types = [], delayIndex = 0) =>
e &&
(!types
.concat(['CallError', 'WrongResponse', 'GetProposalFailure', 'RateLimit', 'DisconnectError'])
.includes(e.name) ||
(e.name !== 'DisconnectError' && delayIndex > maxRetries));
export const shouldThrowError = (error, types = [], delayIndex = 0) => {
if (!error) {
return false;
}

const defaultErrors = ['CallError', 'WrongResponse', 'GetProposalFailure', 'RateLimit', 'DisconnectError'];
const authErrors = ['InvalidToken', 'AuthorizationRequired'];
const errors = types.concat(defaultErrors);

if (authErrors.includes(error.name)) {
// If auth error, reload page.
window.location.reload();
return true;
} else if (!errors.includes(error.name)) {
// If error is unrecoverable, throw error.
return true;
} else if (error.name !== 'DisconnectError' && delayIndex > maxRetries) {
// If exceeded maxRetries, throw error.
return true;
}

return false;
};

export const recoverFromError = (f, r, types, delayIndex) =>
new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/view/LogTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class LogTable extends Component {
type : PropTypes.string,
timestamp: PropTypes.string,
message : PropTypes.string,
}).isRequired,
}),
};
constructor() {
super();
Expand Down