From 4e834b3f2445e187c7970f307b5a5fbaf625f656 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 11 Feb 2026 16:34:42 +0100 Subject: [PATCH] Add `error_code` and `action_url` to some API errors --- app/controllers/api/base_controller.rb | 10 ++++++---- app/controllers/application_controller.rb | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 68c4f3962a8..0d64faab540 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -64,13 +64,15 @@ class Api::BaseController < ApplicationController def require_user! if !current_user - render json: { error: 'This method requires an authenticated user' }, status: 422 + render json: { error: 'This method requires an authenticated user', error_code: 'auth_required' }, status: 422 elsif !current_user.confirmed? - render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403 + render json: { error: 'Your login is missing a confirmed e-mail address', error_code: 'unconfirmed_email' }, status: 403 elsif !current_user.approved? - render json: { error: 'Your login is currently pending approval' }, status: 403 + render json: { error: 'Your login is currently pending approval', error_code: 'account_pending_approval' }, status: 403 + elsif current_user.missing_2fa? + render json: { error: 'Your account requires two-factor authentication', error_code: 'unmet_2fa_requirement', action_url: mfa_setup_path }, status: 403 elsif !current_user.functional? - render json: { error: 'Your login is currently disabled' }, status: 403 + render json: { error: 'Your login is currently disabled', error_code: 'account_disabled' }, status: 403 else update_user_sign_in end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a19fcc7a0ae..580894cb1d1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -88,13 +88,13 @@ class ApplicationController < ActionController::Base format.json do if !current_user.confirmed? - render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403 + render json: { error: 'Your login is missing a confirmed e-mail address', error_code: 'unconfirmed_email' }, status: 403 elsif !current_user.approved? - render json: { error: 'Your login is currently pending approval' }, status: 403 + render json: { error: 'Your login is currently pending approval', error_code: 'account_pending_approval' }, status: 403 elsif current_user.missing_2fa? - render json: { error: 'Your account requires two-factor authentication' }, status: 403 + render json: { error: 'Your account requires two-factor authentication', error_code: 'unmet_2fa_requirement', action_url: mfa_setup_path }, status: 403 elsif !current_user.functional? - render json: { error: 'Your login is currently disabled' }, status: 403 + render json: { error: 'Your login is currently disabled', error_code: 'account_disabled' }, status: 403 end end end