don't crash on missing content type

400 is more apropriate than 500
pull/2554/head
Jan Sandbrink 10 years ago
parent 527717c9c3
commit 7bfd3e3325
  1. 1
      config/locales/de.yml
  2. 1
      config/locales/en.yml
  3. 5
      lib/api/v3/render/render_api.rb

@ -1671,6 +1671,7 @@ de:
invalid_user_status_transition: "Für diesen Nutzeraccount ist die angeforderte Statusänderung nicht zulässig."
invalid_resource:
"Für die Eigenschaft '%{property}' wird eine Ressource vom Typ '%{expected}' erwartet. Gesandt wurde der Typ '%{actual}'."
missing_content_type: "nicht angegeben"
multiple_errors: "Die Integrität mehrerer Eigenschaften wurde verletzt."
parse_error: "Die Abfrage enthielt kein valides JSON."
writing_read_only_attributes: "Nur-lesbare Eigeschaften dürfen nicht geschrieben werden."

@ -1662,6 +1662,7 @@ en:
invalid_resource:
"For property '%{property}' a resource of type '%{expected}' is expected but got a resource of type '%{actual}'."
invalid_user_status_transition: "The current user account status does not allow this operation."
missing_content_type: "not specified"
multiple_errors: "Multiple fields violated their constraints."
parse_error: "The request body was neither empty, nor did it contain a single JSON object."
writing_read_only_attributes: "You must not write a read-only attribute."

@ -42,10 +42,11 @@ module API
def check_content_type
actual = request.content_type
unless actual.starts_with? SUPPORTED_MEDIA_TYPE
unless actual && actual.starts_with?(SUPPORTED_MEDIA_TYPE)
bad_type = actual || I18n.t('api_v3.errors.missing_content_type')
message = I18n.t('api_v3.errors.invalid_content_type',
content_type: SUPPORTED_MEDIA_TYPE,
actual: actual)
actual: bad_type)
fail API::Errors::InvalidRequestBody, message
end

Loading…
Cancel
Save