Git Product home page Git Product logo

Comments (6)

weigao123 avatar weigao123 commented on July 27, 2024

你希望包含哪些异常信息,颗粒度是怎么样的,这个功能可以帮助你解决业务上的什么问题呢?

from drouter.

imcloud avatar imcloud commented on July 27, 2024

你希望包含哪些异常信息,颗粒度是怎么样的,这个功能可以帮助你解决业务上的什么问题呢?

比如打开一本书时,第一层拦截是检查登录,第二层拦截是检查是否已付费购买,第二层还可以细分以包月制购买的是否到期,总之被拦截的可能性很多,但启动路由的一端却无从知晓。

设计上,最简单可以是一个code,也可以封装为一个error对象,我相信你们设计经验更丰富会找到合适的办法

from drouter.

weigao123 avatar weigao123 commented on July 27, 2024

是个好提议,现在的拦截和result是没有建立任何联系的,你应该是通过在request中增加了参数,这样确实不优雅,应该从result去拿比较合理。
是不是可以这样,在返回的result里增加一个statusCode属性,预定义几个,业务方也可以定义自己的。
在拦截的时候可以传递一个statusCode过来,这样在result中就可以获取到了

// status code example
// Users can customize their own status code
public static final int SUCCESS   = 200;
public static final int NOT_FOUND = 404;
public static final int INTERCEPT = 500;

from drouter.

weigao123 avatar weigao123 commented on July 27, 2024

// 拦截,附带错误码
request.getInterceptor().onInterrupt(500);

// 通过result中获取错误码
DRouter.build("/activity/interceptor")
.start(this) { result ->
Toast.makeText(this@MainActivity, "状态码: ${result.statusCode}", Toast.LENGTH_LONG).show()
}

这样是否符合你的诉求?如果有更好的建议欢迎交流。

from drouter.

imcloud avatar imcloud commented on July 27, 2024

// 拦截,附带错误码
request.getInterceptor().onInterrupt(500);
// 通过result中获取错误码
DRouter.build("/activity/interceptor")
.start(this) { result ->
Toast.makeText(this@MainActivity, "状态码: ${result.statusCode}", Toast.LENGTH_LONG).show()
}

这样是否符合你的诉求?如果有更好的建议欢迎交流。

是的,这样设计好很多

from drouter.

weigao123 avatar weigao123 commented on July 27, 2024

OK,代码已提交,感谢反馈
api 'io.github.didi:drouter-api:2.4.6'

from drouter.

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.