Sha256: 6c17ae3658dc0be79e01a83bc947eca449a697f89c8985afd3366167329dffe9

Contents?: true

Size: 1.82 KB

Versions: 36

Compression:

Stored size: 1.82 KB

Contents

# typed: false
# frozen_string_literal: true

module Hephaestus
  module Responses
    def no_content
      head(:no_content)
    end

    def okay
      render(
        json: {
          message: "OK",
        }.to_json,
        status: :ok,
      )
    end

    def created
      render(
        json: {
          message: "Created",
        }.to_json,
        status: :created,
      )
    end

    def bad_request
      render(
        json: {
          errors: [
            {
              message: "Bad Request",
            },
          ],
        }.to_json,
        status: :bad_request,
      )
    end

    def forbidden
      render(
        json: {
          errors: [
            {
              message: "Forbidden",
            },
          ],
        }.to_json,
        status: :forbidden,
      )
    end

    def not_acceptable
      render(
        json: ::Hephaestus::ErrorSerializer.format("Not Acceptable").to_json,
        status: :not_acceptable,
      )
    end

    def not_found
      render(
        json: ::Hephaestus::ErrorSerializer.format("Not Found").to_json,
        status: :not_found,
      )
    end

    def service_unavailable(msg)
      render(
        json: {
          errors: [
            {
              message: "Service Unavailable: #{msg}",
            },
          ],
        }.to_json,
        status: :service_unavailable,
      )
    end

    def bad_gateway
      render(
        json: {
          errors: [
            {
              message: "Bad Gateway",
            },
          ],
        }.to_json,
        status: :bad_gateway,
      )
    end

    def internal_server_error
      render(
        json: {
          errors: [
            {
              message: "Internal Server Error",
            },
          ],
        }.to_json,
        status: :internal_server_error,
      )
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
hephaestus-0.8.7.4 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.7.3 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.7.2 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.7.1 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.7 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.6 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.5 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.4.1 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.4 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.3.4 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.3.3 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.3.2 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.3.1 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.3 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.2 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.1 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.8.0 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.7.7.2 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.7.7 app/controllers/concerns/hephaestus/responses.rb
hephaestus-0.7.6.2 app/controllers/concerns/hephaestus/responses.rb