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

make status customizable #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yormy
Copy link

@yormy yormy commented May 20, 2023

Allow for custom status code return
Example:

            if (data.password === 'Welkom1!') {
                return {
                    data: 'oke',
                    header: {
                        status: 401,
                    },
                };
            }

@nutboltu nutboltu self-requested a review July 5, 2023 11:49
const data = response(request);

let status = 200;
const customStatusCode = data?.header?.status;
Copy link
Collaborator

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?

if (customStatusCode) {
status = customStatusCode;
}
delete data.header;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we pass the header?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to allow the status to be customizable inside the function.
And at the same time leaving the rest of the code alone. The status might be important to mock, the rest of the header not so.
This allows to set the status code based on conditionals in the response function. The current status in the main header is not passed in the request, so you cannot determine how to set anything at that level

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.

None yet

2 participants