title: Dio/Flutter - unable to get http error code, invalid error thrown by Dio
body: <p>My code is simple:</p>
  <pre><code>try {
    var response = await dio.post(url, data: body);
  } on DioError catch (e) {
    print(e.toString());
    throw TextException(Strings.sign_in_error);
  }
  </code></pre>
  <p>So when server throws error code 401, expected result is dio error type response. Instead, I'm getting DioErrorType default with message &quot;Bad state: no element&quot; and response field set to null. So  I can't event get http error code.</p>
  <p>Server response:</p>
  <pre><code>{&quot;type&quot;:&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html&quot;,&quot;title&quot;:&quot;Unauthorized&quot;,&quot;status&quot;:401,&quot;detail&quot;:&quot;access denied&quot;}
  </code></pre>