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

How to use mock.js to generate response that has status 403 or 400 ? #501

Open
Alextraa opened this issue Feb 24, 2023 · 3 comments
Open

Comments

@Alextraa
Copy link

I tried to use the following code to generate 400 response and it did not work.So what is the right way to generate a 400 or 403 response with mock.js? Thank you very much.

export default {
  getCurve: config => {
    console.log(config)
    const {curve_index,test_id}=param2Obj(config.url)

    let results = [];
    let curve1 = [];
    let curve2 = [];
    let curve3 = [];
    for (let i = 0; i < 3000; i++) {
      curve1.push(Math.random() * 300)
    }
    results.push(curve1)

    for (let i = 0; i < 3000; i++) {
      curve2.push(Math.random() * 500)
    }
    results.push(curve2)

    for (let i = 0; i < 3000; i++) {
      curve3.push(Math.random() * 700)
    }
    results.push(curve3)
    console.log(results)
    if (test_id == '1234') {
      if (curve_index < 2) {
        return {
          code: 200,
          data: results[curve_index],
          count_data: 3
        }
      }
      else {
        return {
          status: 400,
          data: results[curve_index],
          count_data: 3
        }
      }
    }
  }
}

The response that code generate :

{
data:{status:400,...}
...
status: 200
statusText: "OK"
}
@sharywkd
Copy link

sharywkd commented Feb 24, 2023 via email

@wll8
Copy link

wll8 commented Feb 24, 2023

Try mock-server based on mockjs package?

@Alextraa
Copy link
Author

Try mock-server based on mockjs package?

Thank you ! I will try mock-server.

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

3 participants