Mime :: Type :: InvalidMimeType(“ charset = utf-8”不是有效的MIME类型)

时间:2019-12-03 21:16:31

标签: ruby-on-rails

自升级到Rails 6之后,我们开始出现以下错误:Mime::Type::InvalidMimeType ("charset=utf-8" is not a valid MIME type)。我认为charset=utf-8作为MIME类型没有任何意义,但无法挽救这些错误:

  rescue_from Mime::Type::InvalidMimeType, with: :raise_not_found

是否有可能在击中我们的控制器之前引发此异常?

1 个答案:

答案 0 :(得分:0)

Mime::Type::InvalidMimeType已添加以下PR:https://github.com/rails/rails/pull/35753

This PR adds the InvalidMimeType in the default rescue_responses from
the ExceptionWrapper and will return a 406.

有关rescue_responses的更多信息:https://guides.rubyonrails.org/configuring.html#configuring-action-dispatch

您是否尝试过以下解决方案:https://stackoverflow.com/a/52475865/4414956?猴子补丁或从rescue_responses中删除InvalidMimeType并自行处理。