+
+ if http_accept_language.compatible_language_from(locales).nil?
+ http_accept_language.user_preferred_languages = http_accept_language.user_preferred_languages.collect do |pl|
+ pls = [pl]
+
+ while pl.match(/^(.*)-[^-]+$/)
+ pls.push($1) if locales.include?($1) || locales.include?($1.to_sym)
+ pl = $1
+ end
+
+ pls
+ end.flatten
+ end
+
+ http_accept_language.compatible_language_from(locales) || I18n.default_locale
+ end
+
+ helper_method :select_locale
+
+ def api_call_handle_error
+ yield
+ rescue ActiveRecord::RecordNotFound => ex
+ render :text => "", :status => :not_found
+ rescue LibXML::XML::Error, ArgumentError => ex
+ report_error ex.message, :bad_request
+ rescue ActiveRecord::RecordInvalid => ex
+ message = "#{ex.record.class} #{ex.record.id}: "
+ ex.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{ex.record[attr].inspect})" }
+ report_error message, :bad_request
+ rescue OSM::APIError => ex
+ report_error ex.message, ex.status
+ rescue AbstractController::ActionNotFound => ex
+ raise
+ rescue StandardError => ex
+ logger.info("API threw unexpected #{ex.class} exception: #{ex.message}")
+ ex.backtrace.each { |l| logger.info(l) }
+ report_error "#{ex.class}: #{ex.message}", :internal_server_error