0

I do have such a code:

enum State {
    SUCCESS = 'success',
    ERROR = 'error'
}

const files: File[] = [...some files here];
const toBase64 = (file: File): Observable<string>; //this works 100% fine
const request = (base64: string) => service.upload(base64);

function buildRequest(file: File) {
    return toBase64(file).pipe(
        switchMap(base64 => this.request(base64)),
        map(() => State.SUCCESS),
        catchError((err) => {
            console.error(err);
            return of(State.ERROR);
        })
    );
}

from(files).pipe(
    concatMap(entry => buildRequest(entry)),
    scan((fileNo, result, index) => {
        // some code here
        return fileNo + 1;
    })
).subscribe();

Now, when every api calls return 400, all those calls are executed When first api call returns 200, only this call is executed, but the rest are not.

2
  • please share the code for requestWithMapAndCatchErrorThatReturnsValueForEachState Commented Apr 25, 2024 at 11:25
  • @NarenMurali I have edited question with more code Commented Apr 25, 2024 at 11:52

1 Answer 1

0

Seems some other function caused bad behavior (fileToBase64Observable) which I need to rework. Thank you all :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.