|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class ErrorCode |
| 4 | + InvalidErrorCode = Class.new(StandardError) |
| 5 | + |
| 6 | + def self.validate_error_code!(error_code) |
| 7 | + return unless error_code.is_a?(Symbol) |
| 8 | + return if Rails.env.production? |
| 9 | + |
| 10 | + raise InvalidErrorCode, error_code unless error_codes.include?(error_code) |
| 11 | + end |
| 12 | + |
| 13 | + def self.error_codes |
| 14 | + { |
| 15 | + missing_permission: { description: 'The user is not permitted to perform this operation' }, |
| 16 | + missing_parameter: { description: 'Not all required parameters are present' }, |
| 17 | + cannot_remove_last_administrator: { description: 'This action would remove the last administrator' }, |
| 18 | + cannot_remove_last_admin_ability: { description: 'This action would remove the last administrative ability' }, |
| 19 | + cannot_delete_last_admin_role: { description: 'This action would remove the last administrative role' }, |
| 20 | + inconsistent_namespace: { description: 'Resources are from different namespaces' }, |
| 21 | + runtime_mismatch: { description: 'Resources are from different runtimes' }, |
| 22 | + generic_key_not_found: { description: 'The given key was not found in the data type' }, |
| 23 | + no_primary_runtime: { description: 'The project does not have a primary runtime' }, |
| 24 | + invalid_external_identity: { description: 'This external identity is invalid' }, |
| 25 | + external_identity_does_not_exist: { description: 'This external identity does not exist' }, |
| 26 | + identity_validation_failed: { description: 'Failed to validate the external identity' }, |
| 27 | + missing_identity_data: { description: 'This external identity is missing data' }, |
| 28 | + registration_disabled: { description: 'Self-registration is disabled' }, |
| 29 | + mfa_failed: { description: 'Invalid MFA data provided' }, |
| 30 | + mfa_required: { description: 'MFA is required' }, |
| 31 | + invalid_login_data: { description: 'Invalid login data provided' }, |
| 32 | + totp_secret_already_set: { description: 'This user already has TOTP set up' }, |
| 33 | + wrong_totp: { description: 'Invalid TOTP code provided' }, |
| 34 | + invalid_verification_code: { description: 'Invalid verification code provided' }, |
| 35 | + unmodifiable_field: { description: 'The user is not permitted to modify this field' }, |
| 36 | + failed_to_invalidate_old_backup_codes: { description: 'The old backup codes could not be deleted' }, |
| 37 | + failed_to_save_valid_backup_code: { description: 'The new backup codes could not be saved' }, |
| 38 | + invalid_setting: { description: 'Invalid setting provided' }, |
| 39 | + |
| 40 | + primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' }, |
| 41 | + secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' }, |
| 42 | + tertiary_level_exceeds_parameters: { description: '', deprecation_reason: 'Outdated concept' }, |
| 43 | + } |
| 44 | + end |
| 45 | +end |
| 46 | + |
| 47 | +ErrorCode.prepend_extensions |
0 commit comments