{"record":{"id":"bfbe077bd146eb03","repo":"ruby-grape/grape","slug":"status-code-must-be-integer-or-symbol","errorCode":null,"errorMessage":"Status code must be Integer or Symbol.","messagePattern":"Status code must be Integer or Symbol\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/grape/dsl/inside_route.rb","lineNumber":69,"sourceCode":"          status 302\n          body_message ||= \"This resource has been moved temporarily to #{url}.\"\n        end\n        header 'Location', url\n        content_type 'text/plain'\n        body body_message\n      end\n\n      # Set or retrieve the HTTP status code.\n      #\n      # @param status [Integer] The HTTP Status Code to return for this request.\n      def status(status = nil)\n        return @status || default_status if status.nil?\n\n        case status\n        when Symbol, Integer\n          @status = Rack::Utils.status_code(status)\n        else\n          raise ArgumentError, 'Status code must be Integer or Symbol.'\n        end\n      end\n\n      # Set response content-type\n      def content_type(val = nil)\n        return header(Rack::CONTENT_TYPE, val) if val\n\n        header[Rack::CONTENT_TYPE]\n      end\n\n      # Allows you to define the response body as something other than the\n      # return value.\n      #\n      # @example\n      #   get '/body' do\n      #     body \"Body\"\n      #     \"Not the Body\"\n      #   end","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/ruby-grape/grape/blob/22d7975629846a3c0c7bd2b34e140a7a1b4af8f6/lib/grape/dsl/inside_route.rb#L51-L87","documentation":"The `status` helper inside a Grape route stores the HTTP status code for the response. It only accepts an Integer (e.g. 201) or a Symbol resolvable by Rack::Utils.status_code (e.g. :created); Rack requires a concrete numeric code at render time. Any other class - most commonly a String like '201' or 'Created' - raises 'Status code must be Integer or Symbol.'.","triggerScenarios":"`status '201'` or `status 'Created'` (String read from config, an env var, or a client-supplied value). `status :not_found` works, but `status 'not_found'` (string symbol) raises. Passing an object whose to_s is a status, e.g. `status some_model.state`.","commonSituations":"Forwarding an upstream service's status read as a String from JSON/HTTP. Driving status from configuration or ENV variables without conversion. Copying examples from Rack/Sinatra-style code that use strings.","solutions":["Pass an Integer: `status 201`.","Pass a Rack-resolvable Symbol: `status :created`.","Normalize dynamic values before calling status: `status Integer(v)` for numeric strings or `status v.to_sym` for names, guarding with a whitelist."],"exampleFix":"# before\nstatus ENV.fetch('OVERRIDE_STATUS', '201') # String raises\n\n# after\nstatus Integer(ENV.fetch('OVERRIDE_STATUS', '201'))\n\n# or a name-based value\nstatus ENV.fetch('OVERRIDE_STATUS_NAME', 'created').to_sym","handlingStrategy":"type-guard","validationCode":"def normalize_status(value)\n  case value\n  when Integer then value\n  when Symbol then value\n  when String then value.match?(/\\A\\d+\\z/) ? Integer(value) : value.to_sym\n  else raise ArgumentError, \"unusable status: #{value.inspect}\"\n  end\nend\n\nstatus normalize_status(ENV.fetch('OVERRIDE_STATUS', '201'))","typeGuard":"def valid_status?(value) = value.is_a?(Integer) || (value.is_a?(Symbol) && Rack::Utils::HTTP_STATUS_CODES.key?(Rack::Utils.status_code(value)))","tryCatchPattern":null,"preventionTips":["Hardcode Integer literals for known statuses; reserve Symbols for readability (:created, :no_content).","Convert inbound strings once at the trust boundary (controller entry), not at the `status` call.","Whitelist acceptable statuses when echoing upstream codes."],"tags":["grape","http-status","status","argument-type","rack"],"backgroundTag":"invalid-http-status-code","analyzedSha":"22d7975629846a3c0c7bd2b34e140a7a1b4af8f6","analyzedAt":"2026-08-21T17:03:54.627Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}