Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should return true for retryable errors', () => {
[
status.OK,
status.CANCELLED,
status.UNKNOWN,
status.DEADLINE_EXCEEDED,
status.RESOURCE_EXHAUSTED,
status.ABORTED,
status.INTERNAL,
status.UNAVAILABLE,
status.DATA_LOSS,
].forEach((code: status) => {
const shouldRetry = retrier.retry({code} as StatusObject);
assert.strictEqual(shouldRetry, true);
});
});
it('should reset the failure count on OK', () => {
retrier.retry({code: status.CANCELLED} as StatusObject);
retrier.retry({code: status.OK} as StatusObject);
assert.strictEqual(retrier.createTimeout(), 0);
});
retry(err: StatusObject): boolean {
if (err.code === status.OK || err.code === status.DEADLINE_EXCEEDED) {
this.failures = 0;
} else {
this.failures += 1;
}
return RETRY_CODES.includes(err.code);
}
}
constructor (stream) {
super();
this.handler = null;
this.stream = stream;
this.cancelled = false;
this.deadline = null;
this.compression = new CompressionFilter();
this.metadataSent = false;
this.status = { code: Status.OK, details: 'OK', metadata: null };
this.stream.on('drain', onStreamDrain.bind(this));
this.stream.once('error', onStreamError.bind(this));
this.stream.once('close', onStreamClose.bind(this));
}
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {StatusObject, status} from '@grpc/grpc-js';
/*!
* retryable status codes
*/
export const RETRY_CODES: status[] = [
status.OK,
status.CANCELLED,
status.UNKNOWN,
status.DEADLINE_EXCEEDED,
status.RESOURCE_EXHAUSTED,
status.ABORTED,
status.INTERNAL,
status.UNAVAILABLE,
status.DATA_LOSS,
];
/**
* Used to track pull requests and determine if additional requests should be
* made, etc.
*
* @class
* @private