1

I make an HTTP call in flutter for checking the username and password on my login page. If I put the right username and password, I will get a status code of 200 OK! Everything is fine up to this point.

But if I put a wrong username and password, to get my status code 901 for that, flutter throws an exception: Invalid response status code! Maybe the HTTP package just works with the regular status codes (not the individual ones)?

2 Answers 2

3

You definitely don't want to be returning 901. You should be returning a valid understood status code. For example, I'd use 403 (Forbidden). An easy-to-understand list can be found in the Wikipedia entry https://en.wikipedia.org/wiki/List_of_HTTP_status_codes.

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

4 Comments

Thanks - you are right! But is there any way, to create individual status codes, flutter also accepts?
I'd return the 403 code, and then the details in a header. No reason not to use a 403 for Forbidden.
Login was just an example, but I have an use case, where I need to use an indiviual status code. So how can I handle this with flutter?
You need to map it into one of the official codes, with more data in the header to distinguish your subcases.
2

You should return a valid http status code otherwise it will return the error you mentioned:

https://github.com/dart-lang/http/blob/master/lib/src/base_response.dart

2 Comments

Thanks, but do you know, if there is any way to work with custoized status codes?
Sure, you just have to create your own http client.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.