Skip to content

[Feature request] Add response.isOk to check if the response status code is 2xx #793

Closed
@petrpavlik

Description

@petrpavlik

I believe that the community would benefit from adding a simple boolean check whether the status code of the response is acceptable.

I took inspiration from the javascript's fetch API where the response exposes response.ok to check whether the status code is >= 200 and < 300 (see the documentation), and created a simple extension to make my life easier.

extension HTTPClientResponse {
    var isOk: Bool {
        status.code >= 200 && status.code < 300
    }
}

Happy to contribute (and write tests) this if there is interest from the side of the maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions