bergben/ng2-img-tools

Cannot read property 'subscribe' of undefined when error

Closed this issue · 0 comments

If I provide an invalid image file I get this following error.

Cannot read property 'subscribe' of undefined

Reason is that you are not returning an observable at line 23 in img-maxpx-size.service.js

    if (file.type !== "image/jpeg" && file.type !== "image/png") {
        resizedFileSubject.next({ resizedFile: file, reason: "The provided File is neither of type jpg nor of type png.", error: "INVALID_EXTENSION" });
        return;
    }

Which results in no observable to call the subscribe method.

Also, as pointed out in the last issue you should be calling .error for any errors that occur so they can be handled in the error handler of the observable.

Changing it to this allows the error to be correctly handled

    if (file.type !== "image/jpeg" && file.type !== "image/png") {
        resizedFileSubject.error({ resizedFile: file, reason: "The provided File is neither of type jpg nor of type png.", error: "INVALID_EXTENSION" });
        return resizedFileSubject.asObservable();
    }