mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 05:35:40 +08:00
## 🔍 Overview
This update ensures that we unify locales to all show the absolute
date/time when showing the reset time for credit limits.
Reset dates will show consistently as i.e. "December 1st at 4:00pm"
instead of "in 3h"
39 lines
949 B
Ruby
Vendored
39 lines
949 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module AiCreditLimitHandler
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
rescue_from LlmCreditAllocation::CreditLimitExceeded do |e|
|
|
render_credit_limit_error(e)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def render_credit_limit_error(exception)
|
|
allocation = exception.allocation
|
|
|
|
details = {}
|
|
if allocation
|
|
details[:reset_time_relative] = allocation.relative_reset_time
|
|
details[:reset_time_absolute] = allocation.formatted_reset_time
|
|
end
|
|
|
|
user_type = current_user&.admin? ? "admin" : "user"
|
|
reset_time = allocation&.formatted_reset_time.presence || ""
|
|
|
|
message =
|
|
I18n.t(
|
|
"discourse_ai.llm_credit_allocation.limit_exceeded_#{user_type}",
|
|
reset_time: reset_time,
|
|
)
|
|
|
|
render json: {
|
|
error: "credit_limit_exceeded",
|
|
message: message,
|
|
details: details,
|
|
},
|
|
status: :too_many_requests
|
|
end
|
|
end
|