app/controllers/kojac_front_methods.rb in kojac-0.16.0 vs app/controllers/kojac_front_methods.rb in kojac-0.17.0

- old
+ new

@@ -61,32 +61,34 @@ #raise e unless Rails.env.production? Rails.logger.debug e.message Rails.logger.debug e.backtrace.join("\n") unless Rails.env.production? handle_exception(e) if respond_to? :handle_exception + status_code = 422 if e.is_a? ::Pundit::NotAuthorizedError - output = { - error: { - format: 'KojacError', - kind: 'Exception', - errors: [{ - message: e.message - }] - } - } - status = :unauthorized + status_code = 403 + elsif e.is_a? ::StandardExceptions::Exception + status_code = e.status else - output = { - error: { - format: 'KojacError', - kind: 'Exception', - errors: [{ - message: e.message - }] - } - } - status = output[:error] ? :unprocessable_entity : :ok + if output.is_a? Hash + error = output[:error] && output['error'] + status_code = 422 + else + status_code = 500 + end end + status = ::Rack::Utils::HTTP_STATUS_CODES[status_code || 500].downcase.gsub(/\s|-/, '_').to_sym + output = { + error: { + format: 'KojacError', + kind: 'Exception', + errors: [{ + message: e.message, + status: status.to_s, + status_code: status_code + }] + } + } output[:error][:errors][0][:backtrace] = e.backtrace unless Rails.env.production? output end send(:after_process, [aInputJson, output]) if respond_to? :after_process jsono = KojacUtils.to_jsono(output, scope: current_user)