Replies: 2 comments 1 reply
-
Hey, @nirajfu3e. MSW constructs a What is Based on your example, I can only see rest.get('http://localhost', (req, res, ctx) => {
return res(
ctx.status(403),
// No magic: only because your client expects "error.response.status".
ctx.json({ response: { status: 403 } })
)
}) If this is a custom behavior of your client (which it seems to be), you'd have to model around it explicitly. If this doesn't solve it, could you prepare a reproduction repository where I could look into the matter? |
Beta Was this translation helpful? Give feedback.
-
@kettanaito I use it in test environment so I presume it's a response in Node.js. Here is how I am making the request on a Vue app to a Laravel API: api.get('https://localhost/api/').then(
(data) => {
this.data = data
},
(error) => {
console.log(error)
if (error.response.status === 403) {
return;
}
}).finally(() => {
this.loading = false;
}); When I mock the response as you mentioned, it essentially adds the response to the data object as follows: {
data: { response: { status: 403 } },
status: 403,
statusText: 'Forbidden', What I was hoping for is if there was a way to modify the object to be something like below - essentially adding the response as a top level object instead of within the response body data. {
data: { },
response: { status: 403 }
status: 403,
statusText: 'Forbidden', I guess that is not possible or even logical to have a response property but I was wondering if that was possible. I think the best option looks like simply to fix the API response. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I am creating a
403
response like this:This has a
RequestBody
like this:The issue I am having is on my api response from Laravel, the error status comes in
error.response.status
and noterror.status
. Is there anyway we could modify theRequestBody
so that we could have custom properties or entirely custom response or is the only way to fix it changing it in the API sot hat the response to be similar to theRequestBody
?Beta Was this translation helpful? Give feedback.
All reactions