const observable = new Observable((subscriber) => {
const regex = /^\d+$/;
for (const value of values) {
if (!subscriber.active) {
return;
}
if (regex.test(value)) {
subscriber.next(value);
} else {
subscriber.error(`Error: "${value}" must contain ASCII digits only`);
return;
}
}
subscriber.complete();
});Subscriber: error() method / notebook
Subscriber: error() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const values = ["1234", "354567", "87654", "007", "98765", "999"];observable.subscribe({
next(value) {
console.log(value);
},
error(error) {
console.log(error);
},
complete() {
console.log("Checking complete. No errors found.");
},
});const values = ["1234", "354567", "87654", "gg567", "007", "98765"];