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

有没有合适的办法来修改response的data #85

Closed
CoolBerry opened this issue Dec 10, 2019 · 2 comments
Closed

有没有合适的办法来修改response的data #85

CoolBerry opened this issue Dec 10, 2019 · 2 comments

Comments

@CoolBerry
Copy link

想要实现统一修改server返回数据的格式,例如首字母都改成小写。

拦截器似乎无法修改到data,有没有合适的办法来实现这个功能呢?

谢谢。

@MinJieLiu
Copy link

@CoolBerry
试试

request.use(async (ctx, next) => {
  await next();

  const { res } = ctx;
  const { success = false } = res; // 假设返回结果为 : { success: false, errorCode: 'B001' }
  if (!success) {
    // 对异常情况做对应处理
  }
})

@starhu521
Copy link

@CoolBerry
试试

request.use(async (ctx, next) => {
  await next();

  const { res } = ctx;
  const { success = false } = res; // 假设返回结果为 : { success: false, errorCode: 'B001' }
  if (!success) {
    // 对异常情况做对应处理
  }
})

如果需要在判断success之后,把数据整理之后(处理之后结果res为any,没有success字段了)返回出去,怎么操作呢?

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

No branches or pull requests

4 participants