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

feat: add http status code support #346

Open
wants to merge 1 commit into
base: refactoring
Choose a base branch
from

Conversation

sendya
Copy link

@sendya sendya commented Apr 8, 2019

feature add http status code
fix #140 #259

eg:

const login = (options) => {
  const body = JSON.parse(options.body)
  const username = ['admin', 'user', 'super']
  const password = ['admin', 'user', 'super']
  if (!username.includes(body.username) || !password.includes(body.password)) {
    return {
      // 业务状态
      code: -1,
      data: null,
      message: '账号或密码错误',
      // _ 开头的返回体第一层数据 _status 作为 mock 返回的状态码
      // 不传值默认 200
      _status: 401
      // 同理可增加 _headers 自定义返回头
    }
  }

  return {
    // 业务状态
    code: 0,
    data: {
      'id': Mock.mock('@guid'),
      'name': Mock.mock('@name'),
      'username': 'admin',
      'token': Mock.mock('@guid')
    },
    message: '登录成功'
  }
}
Mock.mock(/\/auth\/login/, 'post', login)

This PR allow edits from maintainers.

@sendya sendya force-pushed the feature/http-status-support branch from e42189b to eb4877b Compare April 9, 2019 01:47
@sendya sendya closed this Apr 9, 2019
@sendya sendya reopened this Apr 9, 2019
@lizhongyue248
Copy link

需要的是 http 状态码,不是一个 code 表示业务的代码。
比如 404 的状态码,你后端怎么给我返回 code 。。。

两个概念不一样啊。

@sendya
Copy link
Author

sendya commented Apr 22, 2019

需要的是 http 状态码,不是一个 code 表示业务的代码。
比如 404 的状态码,你后端怎么给我返回 code 。。。

两个概念不一样啊。

认真看,这是标准 http 状态码,不是业务 code

@ZhongMingKun
Copy link

ZhongMingKun commented Sep 24, 2020

你好,ant-design-vue-pro下使用[email protected] _headers设置自定义headers 不生效;希望默认headers包含 'Content-Type': 'application/json; charset=utf-8',毕竟现在的应用场景下用的这个比较多

@ZhongMingKun
Copy link

你好,ant-design-vue-pro下使用[email protected] _headers设置自定义headers 不生效;希望默认headers包含 'Content-Type': 'application/json; charset=utf-8',毕竟现在的应用场景下用的这个比较多

@sendya

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

Successfully merging this pull request may close these issues.

支持伪造ajax请求返回的状态码吗
3 participants