Move status serializer error handling to private method (#29031)
This commit is contained in:
parent
0df86d77fd
commit
2f19ddd1fa
@ -73,11 +73,7 @@ class Api::V1::StatusesController < Api::BaseController
|
|||||||
|
|
||||||
render json: @status, serializer: serializer_for_status
|
render json: @status, serializer: serializer_for_status
|
||||||
rescue PostStatusService::UnexpectedMentionsError => e
|
rescue PostStatusService::UnexpectedMentionsError => e
|
||||||
unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new(
|
render json: unexpected_accounts_error_json(e), status: 422
|
||||||
e.accounts,
|
|
||||||
serializer: REST::AccountSerializer
|
|
||||||
)
|
|
||||||
render json: { error: e.message, unexpected_accounts: unexpected_accounts }, status: 422
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@ -159,6 +155,17 @@ class Api::V1::StatusesController < Api::BaseController
|
|||||||
@status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
|
@status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unexpected_accounts_error_json(error)
|
||||||
|
{
|
||||||
|
error: error.message,
|
||||||
|
unexpected_accounts: serialized_accounts(error.accounts),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def serialized_accounts(accounts)
|
||||||
|
ActiveModel::Serializer::CollectionSerializer.new(accounts, serializer: REST::AccountSerializer)
|
||||||
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
def pagination_params(core_params)
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
params.slice(:limit).permit(:limit).merge(core_params)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user