Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typeahead): Typeahead, Observable error callback. When API call fails, application stops working #1956

Closed
astroanu opened this issue May 4, 2017 · 10 comments · Fixed by #5637

Comments

@astroanu
Copy link

astroanu commented May 4, 2017

How do i write an error callback when the typehead is bound to an http observable. Currently it just prints an error on to the console and the component stops working. My typehead is fetching options by calling a remote url, if the remote server fails i want to show a message to the user.

@astroanu astroanu changed the title typehead, subscriber error callback Typehead, Observable error callback May 4, 2017
@astroanu
Copy link
Author

astroanu commented May 5, 2017

I'm putting the code that is responsible for this here

TypeaheadDirective.prototype.asyncActions = function () {
        var _this = this;
        this.keyUpEventEmitter
            .debounceTime(this.typeaheadWaitMs)
            .mergeMap(function () { return _this.typeahead; })
            .subscribe(function (matches) {
            _this.finalizeAsyncCall(matches);
        }, function (err) {
            console.error(err); <- instead this, call my error handler, or a common ngx bootstrap error handler 
        });
    };

@dilumdarshana
Copy link

Am also having the same issue, when API call fails, application breaks. Doesn't work till refresh the application.

@vlaco
Copy link

vlaco commented Jun 30, 2017

I have a simmilar issue. My API call fails and application breaks when I have set typeaheadMinLength="3" and typeaheadWaitMs="300" and the user starts deleting the input faster than the debounce time, the Observable sends input with length<3 and my API fails. I dont need to show the error to the user, I just need a way to somehow prevent the application from breaking or prevent sending the input with length<3 at all.

@krooshua
Copy link
Contributor

Hi!
Any progress on this issue?

@vlaco
Copy link

vlaco commented Sep 27, 2017

@krooshua I tried your solution and it didn't work for me :/ API still returns an error and the application breaks and won't send any more requests. I solved this by simply adding catch to Observable like this:

this.dataSource = Observable.create((observer: any) => {
      // Runs on every search
      observer.next(this.asyncSelected);
    }).mergeMap((token: string) => this.getStatesAsObservable(token))
.catch((error: any) => {
      // console.log(error);
      return [];
    });

This works for me but there must be a better solution.

@YevheniiaMazur YevheniiaMazur changed the title Typehead, Observable error callback fix(typeahead): Typehead, Observable error callback. When API call fails, application stops working Jan 16, 2018
@YevheniiaMazur YevheniiaMazur changed the title fix(typeahead): Typehead, Observable error callback. When API call fails, application stops working fix(typeahead): Typeahead, Observable error callback. When API call fails, application stops working Jan 16, 2018
@IlyaSurmay
Copy link
Contributor

Typeahead doesn't do any http requests itself, it only takes an Observable as input. So all http errors should be handled outside if this component.

@vlaco
Copy link

vlaco commented Jan 16, 2018

Http error is not the point of this issue. The point is that it shouldn't do anything if input length is less than 3 if typeaheadMinLength="3", it shouldn't accept it as an input and it does. Works perfectly fine if you type slowly enough for the debounce to catch it but if you type any faster it fails. I think there should be some additional input length check.

@astroanu
Copy link
Author

@IlyaSurmay you haven't let the developers exactly handle those errors outside your component. Check the code it's right in front of you.

@IlyaSurmay IlyaSurmay reopened this Jan 19, 2018
@IlyaSurmay
Copy link
Contributor

@astroanu my bad :( We'll come up with plunkr that shows how to handle errors or PR that fixes the issue

@IraErshova
Copy link
Contributor

@astroanu Hi! Do you still have this issue? Typeahead component has had a lot of changes since 2017. I added PR with a new demo for async typeahead. It's not merged yet but you can check how I handle http error.

https://github.com/valor-software/ngx-bootstrap/pull/5637/files#diff-f68a35042d5e6635f58cce1aea50df39

I'm going to close the issue because it's not the issue anymore.
@vlaco your issue is not related to the initial topic of the issue. Could you please open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants