-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
make status customizable #168
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,10 +119,20 @@ export class Faker { | |
|
||
if (matched) { | ||
const { response, status, delay = 0 } = matched; | ||
|
||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
if (typeof response === 'function') { | ||
resolve(new Response(url, status, response(request))); | ||
const data = response(request); | ||
|
||
let status = 200; | ||
const customStatusCode = data?.header?.status; | ||
if (customStatusCode) { | ||
status = customStatusCode; | ||
} | ||
delete data.header; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we pass the header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to allow the status to be customizable inside the function. |
||
|
||
resolve(new Response(url, status, data)); | ||
} else { | ||
resolve(new Response(url, status, response)); | ||
} | ||
|
@@ -141,6 +151,13 @@ export class Faker { | |
setTimeout(() => { | ||
if (typeof response === 'function') { | ||
const data = response(new Request(url, { method, body })); | ||
let status = 200; | ||
const customStatusCode = data?.header?.status; | ||
if (customStatusCode) { | ||
status = customStatusCode; | ||
} | ||
delete data.header; | ||
|
||
request.respond( | ||
+status, | ||
defaultResponseHeaders, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yormy can you please help understand why we are passing status inside the header?