moduleGrapemoduleExceptionsclassBase<StandardErrorBASE_MESSAGES_KEY='grape.errors.messages'.freezeBASE_ATTRIBUTES_KEY='grape.errors.attributes'.freezeFALLBACK_LOCALE=:enattr_reader:status,:message,:headersdefinitialize(status: nil,message: nil,headers: nil,**_options)@status=status@message=message@headers=headersenddef[](index)sendindexendprotected# TODO: translate attribute first# if BASE_ATTRIBUTES_KEY.key respond to a string message, then short_message is returned# if BASE_ATTRIBUTES_KEY.key respond to a Hash, means it may have problem , summary and resolutiondefcompose_message(key,**attributes)short_message=translate_message(key,**attributes)ifshort_message.is_a?Hash@problem=problem(key,**attributes)@summary=summary(key,**attributes)@resolution=resolution(key,**attributes)[['Problem',@problem],['Summary',@summary],['Resolution',@resolution]].reduce('')do|message,detail_array|message<<"\n#{detail_array[0]}:\n#{detail_array[1]}"unlessdetail_array[1].blank?messageendelseshort_messageendenddefproblem(key,attributes)translate_message("#{key}.problem".to_sym,attributes)enddefsummary(key,attributes)translate_message("#{key}.summary".to_sym,attributes)enddefresolution(key,attributes)translate_message("#{key}.resolution".to_sym,attributes)enddeftranslate_attributes(keys,**options)keys.mapdo|key|translate("#{BASE_ATTRIBUTES_KEY}.#{key}",default: key,**options)end.join(', ')enddeftranslate_attribute(key,**options)translate("#{BASE_ATTRIBUTES_KEY}.#{key}",default: key,**options)enddeftranslate_message(key,**options)casekeywhenSymboltranslate("#{BASE_MESSAGES_KEY}.#{key}",default: '',**options)whenProckey.callelsekeyendenddeftranslate(key,**options)options=options.dupoptions[:default]&&=options[:default].to_smessage=::I18n.translate(key,**options)message.present??message:fallback_message(key,**options)enddeffallback_message(key,**options)if::I18n.enforce_available_locales&&!::I18n.available_locales.include?(FALLBACK_LOCALE)keyelse::I18n.translate(key,locale: FALLBACK_LOCALE,**options)endendendendend