diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 8d510e98a..4461e4e0d 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -10,29 +10,29 @@ module Api rescue_from Exception do |e| logger.error e.message logger.error e.backtrace.join("\n") - render json: error_body(500, e.message), status: 500 + render json: error_body(500, e.message), status: :internal_server_error end rescue_from Rack::OAuth2::Server::Resource::Forbidden do |e| logger.error e.message - render json: error_body(403, e.message), status: 403 + render json: error_body(403, e.message), status: :forbidden end rescue_from ActiveRecord::RecordNotFound do |e| logger.error e.message message = I18n.t("api.error.not_found") - render json: error_body(404, message), status: 404 + render json: error_body(404, message), status: :not_found end rescue_from ActiveRecord::RecordInvalid do |e| logger.error e.message - render json: error_body(422, e.to_s), status: 422 + render json: error_body(422, e.to_s), status: :unprocessable_entity end rescue_from ActionController::ParameterMissing do |e| logger.error e.message message = I18n.t("api.error.wrong_parameters") + ": " + e.message - render json: error_body(422, message), status: 422 + render json: error_body(422, message), status: :unprocessable_entity end def error_body(code, message) diff --git a/app/controllers/api/v1/comments_controller.rb b/app/controllers/api/v1/comments_controller.rb index 32aa9618f..54b5e4edb 100644 --- a/app/controllers/api/v1/comments_controller.rb +++ b/app/controllers/api/v1/comments_controller.rb @@ -14,7 +14,7 @@ module Api def create @comment = comment_service.create(params[:post_id], params[:body]) comment = comment_as_json(@comment) - render json: comment, status: 201 + render json: comment, status: :created end def index @@ -39,7 +39,10 @@ module Api if report.save head :no_content else - render json: {error: I18n.t("report.status.failed")}, status: 500 + render( + json: {error: I18n.t("report.status.failed")}, + status: :internal_server_error + ) end end diff --git a/app/controllers/api/v1/conversations_controller.rb b/app/controllers/api/v1/conversations_controller.rb index 1d1b6d4e4..ed843cbd3 100644 --- a/app/controllers/api/v1/conversations_controller.rb +++ b/app/controllers/api/v1/conversations_controller.rb @@ -14,7 +14,10 @@ module Api end rescue_from ActiveRecord::RecordNotFound do - render json: {error: I18n.t("conversations.not_found")}, status: 404 + render( + json: {error: I18n.t("conversations.not_found")}, + status: :not_found + ) end def index @@ -44,7 +47,7 @@ module Api render json: { conversation: conversation_as_json(conversation) - }, status: 201 + }, status: :created end def destroy diff --git a/app/controllers/api/v1/likes_controller.rb b/app/controllers/api/v1/likes_controller.rb index 8a7cd0998..c4549d18f 100644 --- a/app/controllers/api/v1/likes_controller.rb +++ b/app/controllers/api/v1/likes_controller.rb @@ -8,11 +8,11 @@ module Api end rescue_from ActiveRecord::RecordNotFound do - render json: I18n.t("likes.not_found"), status: 404 + render json: I18n.t("likes.not_found"), status: :not_found end rescue_from ActiveRecord::RecordInvalid do - render json: I18n.t("likes.create.fail"), status: 404 + render json: I18n.t("likes.create.fail"), status: :not_found end def create diff --git a/app/controllers/api/v1/messages_controller.rb b/app/controllers/api/v1/messages_controller.rb index d843f64c4..76da744be 100644 --- a/app/controllers/api/v1/messages_controller.rb +++ b/app/controllers/api/v1/messages_controller.rb @@ -12,7 +12,10 @@ module Api end rescue_from ActiveRecord::RecordNotFound do - render json: {error: I18n.t("conversations.not_found")}, status: 404 + render( + json: {error: I18n.t("conversations.not_found")}, + status: :not_found + ) end def create @@ -21,13 +24,16 @@ module Api message = current_user.build_message(conversation, text: opts[:body]) message.save! Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message) - render json: message_json(message), status: 201 + render json: message_json(message), status: :created end def index conversation = conversation_service.find!(params[:conversation_id]) conversation.set_read(current_user) - render json: conversation.messages.map {|x| message_json(x) }, status: 201 + render( + json: conversation.messages.map {|x| message_json(x) }, + status: :created + ) end def conversation_service diff --git a/app/controllers/api/v1/streams_controller.rb b/app/controllers/api/v1/streams_controller.rb index 101b3972e..190a0567f 100644 --- a/app/controllers/api/v1/streams_controller.rb +++ b/app/controllers/api/v1/streams_controller.rb @@ -40,9 +40,7 @@ module Api private def stream_responder(stream_klass=nil) - if stream_klass.present? - @stream ||= stream_klass.new(current_user, max_time: max_time) - end + @stream = stream_klass.present? ? stream_klass.new(current_user, max_time: max_time) : @stream render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) } end