2022-09-23 21:00:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-13 14:53:22 +00:00
|
|
|
class Api::V1::Statuses::TranslationsController < Api::V1::Statuses::BaseController
|
2022-09-23 21:00:12 +00:00
|
|
|
before_action -> { doorkeeper_authorize! :read, :'read:statuses' }
|
2024-07-04 14:26:49 +00:00
|
|
|
before_action :require_user!
|
2022-09-23 21:00:12 +00:00
|
|
|
before_action :set_translation
|
|
|
|
|
|
|
|
rescue_from TranslationService::NotConfiguredError, with: :not_found
|
2023-08-29 07:14:44 +00:00
|
|
|
rescue_from TranslationService::UnexpectedResponseError, with: :service_unavailable
|
|
|
|
|
|
|
|
rescue_from TranslationService::QuotaExceededError do
|
|
|
|
render json: { error: I18n.t('translation.errors.quota_exceeded') }, status: 503
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from TranslationService::TooManyRequestsError do
|
|
|
|
render json: { error: I18n.t('translation.errors.too_many_requests') }, status: 503
|
|
|
|
end
|
2022-09-23 21:00:12 +00:00
|
|
|
|
|
|
|
def create
|
|
|
|
render json: @translation, serializer: REST::TranslationSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_translation
|
2024-10-15 13:26:20 +00:00
|
|
|
@translation = TranslateStatusService.new.call(@status, I18n.locale.to_s)
|
2022-09-23 21:00:12 +00:00
|
|
|
end
|
|
|
|
end
|