We had a case where we needed to add some custom error messages on some attributes.
Since this gem used resource.errors.full_messages, error messages would be weird, e.g. "Shipping address some of the line items can't be delivered to this shipping address" instead of just "Some of the line items can't be delivered to this shipping address".
We monkey patched a solution for this:
def error_render_options
errors = { errors: [] }
errors[:errors] << { detail: on_error(:detail) } if on_error(:detail)
resource.errors.messages.each do |attribute, messages|
messages.each do |message|
errors[:errors] << error_response(attribute, message)
end
end if resource.respond_to?(:errors)
errors
end
def error_response(attribute, message)
{
title: I18n.t("json_api.errors.#{status}.title"),
detail: message.capitalize,
source: { parameter: attribute, pointer: "data/attributes/#{attribute}" }
}
end
We had a case where we needed to add some custom error messages on some attributes.
Since this gem used
resource.errors.full_messages, error messages would be weird, e.g. "Shipping address some of the line items can't be delivered to this shipping address" instead of just "Some of the line items can't be delivered to this shipping address".We monkey patched a solution for this: