title: How to return error object in in a HTTP API Future request
body: <p>I am using BLOC Pattern, so my query is how to return some error post HTTP request.
  Suppose if the API returns 200 as a status code I can return the particular model which I have mentioned if there is an error returning from the API like 302, 404 401... so on so how to handle this and return UI to show the error message</p>
  
  <pre><code>Future&lt;SampleModel&gt; getSomeDetails(String ID) async {
      var response =
      await http.get(someURL,
          headers: {'Content-type': 'application/x-www-form-urlencoded',});
      if (response.statusCode == 200) {
        return SampleModel.fromJson(json.decode(response.body));
      } else {
        throw Exception('Failed to load post');// return the error to UI
      }
    }
  </code></pre>
  
  <p>PS: I am also using the observer Pattern</p>