Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Add ability to use function for status #101

@smackfu

Description

@smackfu

For more complex mocks, parrot supports passing a function as the body, which can be matched against the request object to return different responses.

See: https://github.com/americanexpress/parrot/blob/main/packages/parrot-core/src/utils/resolveResponse.js#L31

There are use-cases where it would be convenient to return a different http status code for different requests to the same endpoint.

Currently the status field does not support being passed a function:

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: () => 200
    at ServerResponse.writeHead (_http_server.js:248:11)
    at ServerResponse._implicitHeader (_http_server.js:239:8)
    at write_ (_http_outgoing.js:654:9)
    at ServerResponse.end (_http_outgoing.js:766:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions