premium(text, minimumQuality) {
let attempt = 0;
const attemptFetch = () => {
return new Promise((resolve, reject) => {
this.api.fetch(text).then((response) => {
if (response.quality < minimumQuality) {
reject(new QualityThresholdNotMet(text));
} else {
resolve(response.translation);
}
}).catch((error) => {
reject(error);
});
});
};
const attemptRequestAndFetch = () => {
return new Promise((resolve, reject) => {
this.request(text).then(() => {
attemptFetch().then((response) => {
resolve(response);
}).catch((error) => {
reject(new QualityThresholdNotMet(text));
});
}).catch((error) => {
reject(error)
});
});
};
return attemptFetch().catch((error) => {
attempt++;
if (attempt < 2) {
return attemptRequestAndFetch();
} else {
return Promise.reject(error);
}
});
}
I am stuck in the last task of this exercise. There is just one error left: Test 18 - Premium service > it recognizes insufficient quality
This is the error that I am getting:
Error: expect(received).rejects.toThrow(expected)
Expected constructor: QualityThresholdNotMet
Received constructor: AbusiveClientError
Received message: "Your client has been rejected because of abusive behaviour.·
naDevvo’ yIghoS!"
81 | if (this.values[text] && this.values[text][0]) {
82 | mutex.current = true;
> 83 | callback(new AbusiveClientError());
| ^
84 | return;
85 | }
86 |
at ExternalApi.request (../..<solution>/api.js:83:16)
at request (../..<solution>/service.js:72:18)
at attemptResponse (../..<solution>/service.js:71:14)
at attemptResponse (../..<solution>/service.js:77:13)
at ExternalApi.callback [as request] (../..<solution>/api.js:83:7)
at request (../..<solution>/service.js:72:18)
at attemptResponse (../..<solution>/service.js:71:14)
at attemptResponse (../..<solution>/service.js:77:13)
at ExternalApi.callback [as request] (../..<solution>/api.js:83:7)
at request (../..<solution>/service.js:72:18)
at attemptResponse (../..<solution>/service.js:71:14)
at TranslationService.attemptResponse [as request] (../..<solution>/service.js:86:12)
at request (../..<solution>/service.js:118:18)
at attemptRequestAndFetch (../..<solution>/service.js:117:16)
at attemptRequestAndFetch (../..<solution>/service.js:133:20)
at Object.<anonymous> (../..<solution>/service.spec.js:199:5)
I am just not able to understand how I am getting an abusiveClient error. I am only requesting when it gives error from attemptFetch() function.