Giter Site home page Giter Site logo

restful api 非200状态码问题 about dio HOT 4 CLOSED

cfug avatar cfug commented on July 30, 2024
restful api 非200状态码问题

from dio.

Comments (4)

wendux avatar wendux commented on July 30, 2024

Supported! please update dio to latest version firstly.
you can custom the ValidateStatus of options:

  /// `validateStatus` defines whether the request is successful for a given
  /// HTTP response status code. If `validateStatus` returns `true` ,
  /// the request will be perceived as successful; otherwise, considered as failed.
  ValidateStatus validateStatus;

Examples

dio.options.validateStatus=(int status){
    return status >= 200 && status < 300 || status == 304;
}

from dio.

guodf avatar guodf commented on July 30, 2024

var dio=Dio();
dio.options.validateStatus=(int status){
return status >0;
}
dio.post()

restful api返回错误码为1000,validateStatus无效,依然发生异常

from dio.

wendux avatar wendux commented on July 30, 2024

@guodf 这个status是http状态码,并不是API中定义的错误码

from dio.

lwabish avatar lwabish commented on July 30, 2024

Supported! please update dio to latest version firstly. you can custom the ValidateStatus of options:

  /// `validateStatus` defines whether the request is successful for a given
  /// HTTP response status code. If `validateStatus` returns `true` ,
  /// the request will be perceived as successful; otherwise, considered as failed.
  ValidateStatus validateStatus;

Examples

dio.options.validateStatus=(int status){
    return status >= 200 && status < 300 || status == 304;
}

设置了validateStatus后dart代码确实不需要捕获异常了,但是客户端浏览器的console里还是能看到红色的error提示403,请教下有办法隐藏浏览器的提示嘛?

from dio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.