Fix code style
This commit is contained in:
parent
4370315d6c
commit
2c94994f32
6 changed files with 27 additions and 17 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue