Skip to content

Http::Response.build passing nil status code to HTTP::Response.new #64

@trapped

Description

@trapped

Here the status code is allowed to be nil, causing the compiler to complain:

in ./libs/amethyst/amethyst/base/handler.cr:12: instantiating 'Amethyst::Http::Response#build()'
        response.build
                 ^~~~~
in ./libs/amethyst/amethyst/http/response.cr:23: instantiating 'HTTP::Response:Class#new((Nil | Int32), String, HTTP::Headers)'
        return HTTP::Response.new(@status, @body, headers = @headers)
                              ^~~
instantiating 'HTTP::Response#initialize((Nil | Int32), String, HTTP::Headers, Nil, String, Nil)'
in /Users/giorgio/Documents/crystal/src/http/response.cr:14: instantiating 'HTTP::Response:Class#mandatory_body?((Nil | Int32))'
    if Response.mandatory_body?(@status_code)
                ^~~~~~~~~~~~~~~
in /Users/giorgio/Documents/crystal/src/http/response.cr:77: undefined method '/' for Nil (compile-time type is (Nil | Int32))
    !(status_code / 100 == 1 || status_code == 204 || status_code == 304)

Either Http::Response.new should not allow a nil status code, or Http::Response.build should check for that and use a "default" one.

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