Skip to content

JSONAPI Content-Type in error responses #17

Open
@stevenharman

Description

@stevenharman

I'm wondering if we should be setting the Content-Type response header for JsonapiErrorable#handle_exception and JsonapiErrorable::Validatable#render_errors_for. In our app we've overwritten those two methods in our base API controller to look something like this:

  # Override JsonapiErrorable#handle_exception to ensure correct content type
  def handle_exception(*)
    self.content_type ||= Mime[:jsonapi]
    super
  end

  private

  # Override JsonapiErrorable::Validatable to ensure correct content type
  def render_errors_for(*)
    self.content_type ||= Mime[:jsonapi]
    super
  end

Here we're relying on the Mime::Type being registered - which we're getting by way of jsonapi-rails, which registers it in their Railtie. https://github.com/jsonapi-rb/jsonapi-rails/blob/14a9421658495fe916ec1886834b6adfd764b211/lib/jsonapi/rails/railtie.rb#L34-L36

But this gem could do something similar. Is there a reason not to?

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