Skip to content

Add Plug.Conn.Status.valid?/1 #1156

Description

@halostatue

I’m working on a library that accepts status codes (integer or atom) and want to verify that valid status values are used.

I can do this with:

try
  Plug.Conn.Status.code(value)
  true
rescue
  _ -> false
end

But this seems like it might be more generally useful if built into Plug.Status. Would a PR for this feature be accepted?

As well, it seems that Plug.Conn.Status.code/1 for the integer case isn’t entirely correct given the error raised with an unknown value in reason_phrase/1:

  def code(integer) when integer in 100..999 do
    integer
  end
…

That feels like it should be instead

```elixir
@valid_status_codes Map.keys(Map.merge(statuses, custom_statuses))
def code(integer) when integer in @valid_status_codes do
  integer
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions