Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg-onerror support jsonp #1330

Closed
beliefgp opened this issue Aug 18, 2017 · 10 comments
Closed

egg-onerror support jsonp #1330

beliefgp opened this issue Aug 18, 2017 · 10 comments
Assignees

Comments

@beliefgp
Copy link

当egg-jsonp和egg-onerror共用时,当一个jsonp请求,抛出异常时,会由egg-onerror处理,这时就不会包上callback了

有个想法:

  1. jsonp插件,开放出来包装方法,并且在请求时,在ctx上打个标记。
  2. onerror检测到这个标记,调用包装方法。

可行?可以的话,我提个pr

@popomore
Copy link
Member

如果是已知异常,就 try/catch 将错误信息设置到 ctx.body 上。

@beliefgp
Copy link
Author

这样就和不用egg-onerror没什么区别了

@atian25
Copy link
Member

atian25 commented Aug 19, 2017

onerror 主要用于未捕获异常的兜底处理。

#1086 (comment)

@beliefgp
Copy link
Author

我现在做法就是在ctx上加了throwError,可以设置是否记日志等,然后用egg-onerror来做汇总处理……

@beliefgp
Copy link
Author

要用贯高说的单独一个中间件来做,确实也就解决了这个jsonp的问题,不过在根据相应内容做对应处理,是不是感觉和onerror重复

@popomore
Copy link
Member

@beliefgp 这个算是解决了?

@beliefgp
Copy link
Author

jsonp的pr已经合并,已经对外放出相关api了,这个稍微改下就可以了,这个你们来改,还是我有空提个pr

@atian25
Copy link
Member

atian25 commented Nov 7, 2017

这个还搞么?

@fengmk2
Copy link
Member

fengmk2 commented Nov 7, 2017

@beliefgp 继续搞完?

@beliefgp
Copy link
Author

beliefgp commented Nov 7, 2017

@fengmk2 额……千总……这两天我抽空改改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants