title: Flutter : Handling error Dio Package (404,400 etc)
body: <p>I'm learn searching data by ID with package <strong>DIO</strong> <a href="https://pub.dev/packages/dio" rel="noreferrer">https://pub.dev/packages/dio</a>, my problem is every time I'm type wrong keyword search, the app suddenly crash with debug message <strong>404 Not Found</strong>.</p>
  <p><img src="https://i.stack.imgur.com/HTMVi.png" alt="enter image description here" />
  <br></p>
  <p>I know data not found because I'm type wrong keyword, but I'm already handle this with this code <br></p>
  <pre><code>Widget _searchKeywordMahasiswa() {
      return FutureBuilder&lt;List&lt;Mosque&gt;&gt;(
        future: api.getMahasiswaById(_searchText),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            return Expanded(
              child: ListView.builder(
                shrinkWrap: true,
                itemCount: snapshot.data.length,
                itemBuilder: (BuildContext context, int index) {
                  return Text(snapshot.data[index].id);
                },
              ),
            );
          } else if (!snapshot.data) { &lt;&lt;&lt;&lt;&lt;&lt; IN THIS LINE
            return Center(
              child: Icon(
                Icons.sentiment_very_dissatisfied,
                size: 150.0,
              ),
            );
          }
          return CircularProgressIndicator();
        },
      );
      // return CircularProgressIndicator();
    }
  </code></pre>
  <pre><code>Future&lt;List&lt;Mosque&gt;&gt; getMahasiswaById(String id) async{
      try {
        var apiRespon = await dio.get('${Urls.BASE_API_URL}/mahasiswa/get/id/$id');
        var apiResponJson = apiRespon.data;
        print(apiResponJson);
        return (apiResponJson['data'] as List).map((p)=&gt;Mosque.fromJson(p)).toList();
  
      }on DioError catch (e) { &lt;&lt;&lt;&lt;&lt; IN THIS LINE
        if(e.response.statusCode == 404){
          print(e.response.statusCode);
        }else{
          print(e.message);
          print(e.request);
        }
      }
    }
  </code></pre>
  <blockquote>
  <p>In same case my App crash too if i'm get error <strong>400 Bad Request</strong> And i'm already handle this error but not works.</p>
  </blockquote>
  <p>Can you Help Me With This?</p>