api_exception 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b90703e1bb43fa3822e44d1b51e37a8a9ac66ba6229351e40eeffe7bee4020a
4
- data.tar.gz: 4f806eabfe86079a1dd7882d37c0c3c5fea70e7bb642ed6f628f30bad57c2c0f
3
+ metadata.gz: 98dabbff847276d241f8b6339317135669ea5001b75d936bbc42fc9f001dbcde
4
+ data.tar.gz: 5d1423c28d88c359b727c1de12b76ae593382d6155966644aae31cca6b6352e2
5
5
  SHA512:
6
- metadata.gz: cec3705d7c5049d5a8108743905f8bc44b4441509ab1603a00356194b7035ca5bfea2e0e07e72d0daa3776be64e6d553ad3ef56facadfde3fc40ac446483f0f5
7
- data.tar.gz: d03479ab02b272b25c26b54f4a840ef572ec91aff4123f4b7aec5057edbbf0b37568b6ab355ff7fa3df241618845f43fa658eb31d4d3c801c35b43b242e4b1ab
6
+ metadata.gz: e9554a7292def309a58d54af58e6ad235069dbacd75a5c5c9ea494f55b89310e4e5a7ce610fe408e58795be5b6d656209139cdef1eb4c30fe202e4c1ed375540
7
+ data.tar.gz: 7acb28722554c9864bc66154a8ad8a2fe7e655d9f75a0d1c4e4d83c3826aa1f39ec67f45858fd369c0f330cf21c0d5b45380f7ac45cc9339a8de5a1c8d6b8610
data/README.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # ApiException
2
- Short description and motivation.
2
+ This gem is a compilation of common errors that can be encountered with File, Model and Controller handling
3
3
 
4
4
  ## Usage
5
- How to use my plugin.
5
+ ```ruby
6
+ # This is the base class
7
+ # New exception handlers should inherit from this class
8
+ ApiException::BaseException
9
+
10
+ # You can initialize with the following params
11
+ # error_type -> This argument should be a symbol
12
+ # errors -> This argument should be an array of string errors
13
+ # params -> Should be a hash as params for I18n.t translations
14
+ # platform -> Should specify where this error is rendered from, 'API' value is by default
15
+ ApiException::BaseException.new(:UNKNOWN_ERROR, ["Something went wrong"], { process: "" })
16
+ ```
6
17
 
7
18
  ## Installation
8
19
  Add this line to your application's Gemfile:
@@ -1,20 +1,14 @@
1
1
  en:
2
2
  base_exceptions:
3
- timeout: "Could not connect to %{provider}"
4
- invalid_user: Invalid user
5
- duplicated_emails: Some user emails are duplicated
6
- unauthorized_user: User is unauthorized to do this action
7
3
  standard_error: "%{message}"
8
4
  action_not_permitted: Action is not permitted
9
- invalid_date_range: Invalid date range
10
- authentication_failure: Verify authentication parameters.
11
5
  model_exceptions:
12
6
  record_not_found: "Record not found for %{model}"
13
7
  invalid_status_change: "Cannot change status from %{original_status} to %{new_status}"
14
8
  invalid_update: "Cannot update %{model} with the requested parameters"
15
9
  not_unique_record: ID should be unique for this datatype
16
10
  invalid_attributes: "Some attributes provided are not valid or allowed for %{model} model"
17
- update_conflict: Update conflict. Please check the attributes and retry again.
11
+ update_conflict: Update conflict. Please check the attributes and retry again
18
12
  unique_combination: There is a unique combination of attributes already in use
19
13
  required_dependency_missing: "%{model} depends of %{dependency_model} relation before save"
20
14
  validation_failed: There are some validation failed, before save this record ensure to pass them
@@ -27,4 +21,21 @@ en:
27
21
  invalid_extension: "The file has an invalid extension, allowed extensions are: %{extension_allowed}"
28
22
  cant_decode: The file could not be decoded
29
23
  max_size_exceeded: "The file exceeds the maximum defined size: %{max_size}"
30
- invalid_content: The file does not have valid content
24
+ invalid_content: The file does not have valid content
25
+ request_exceptions:
26
+ timeout: "The response timeout was exceeded: %{timeout}"
27
+ request_format_error: The request format is invalid
28
+ invalid_response: The server response is invalid
29
+ request_sever_error: An error occurred processing the request
30
+ connection_refused: The server rejected the request
31
+ http_error_code: There was a problem with the request
32
+ encoding_error: A problem occurred with the encoding of parameters or headers
33
+ ssl_error: An error occurred while verifying the SSL certificate
34
+ dns_error: An error occurred with the DNS configuration
35
+ authentication_error: Authentication error
36
+ user_exceptions:
37
+ duplicated_user: Duplicate user
38
+ authentication_error: The user could not be authenticated
39
+ permission_denied: The user does not have the permissions to perform this action
40
+ insecure_password_storage: The password must be strong
41
+ profile_update_error: The user data could not be updated
@@ -1,13 +1,7 @@
1
1
  es:
2
2
  base_exceptions:
3
- timeout: "No se pudo conectar a %{provider}"
4
- invalid_user: Usuario invalido
5
- duplicated_emails: Algunos e-mails están duplicados
6
- unauthorized_user: Usuario no autorizado para realizar esta acción
7
3
  standard_error: "%{message}"
8
4
  action_not_permitted: La acción no está permitida
9
- invalid_date_range: Rango de fechas inválido
10
- authentication_failure: Verifique parámetros de autenticación.
11
5
  model_exceptions:
12
6
  record_not_found: "Registro no encontrado para %{model}"
13
7
  invalid_status_change: "No se puede cambiar el status de %{original_status} a %{new_status}"
@@ -27,4 +21,21 @@ es:
27
21
  invalid_extension: "El archivo tiene una extension invalida, las extensiones permitidas son: %{extension_allowed}"
28
22
  cant_decode: El archivo no pudo ser decodificado
29
23
  max_size_exceeded: "El archivo excede el tamaño maximo definido de %{max_size}"
30
- invalid_content: El archivo no tiene un contenido valido
24
+ invalid_content: El archivo no tiene un contenido valido
25
+ request_exceptions:
26
+ timeout: "Se excedió el tiempo de respuesta: %{timeout}"
27
+ request_format_error: El formato de la petición no es válido
28
+ invalid_response: La respuesta del servidor no es válida
29
+ request_sever_error: Ocurrio un error procesando la solicitud
30
+ connection_refused: El servidor rechazo la solicitud
31
+ http_error_code: Hubo un problema en la solicitud
32
+ encoding_error: Se produjo un error con la codificación de parámetros o encabezados
33
+ ssl_error: Se produjo un error al verificar el certificado SSL
34
+ dns_error: Se produjo un error con la configuración de DNS
35
+ authentication_error: Error de autenticación
36
+ user_exceptions:
37
+ duplicated_user: Usuario duplicado
38
+ authentication_error: No fue posible autenticar al usuario
39
+ permission_denied: El usuario no cuenta con los permisos para realizar esta acción
40
+ insecure_password_storage: La contraseña debe ser segura
41
+ profile_update_error: No fue posible actualizar los datos del usuario
@@ -11,6 +11,8 @@ module ApiException
11
11
  define_attributes(error_type, errors, params, platform)
12
12
  end
13
13
 
14
+ private
15
+
14
16
  def parse_message
15
17
  @parsed_message = @hash_message
16
18
 
@@ -24,20 +26,11 @@ module ApiException
24
26
  @parsed_message
25
27
  end
26
28
 
27
- private
28
-
29
29
  # Base error code should between 1 and 100
30
30
  def error_code_map
31
31
  {
32
- TIMEOUT: { code: 1, message: find_translation(:timeout) },
33
- INVALID_USER: { code: 2, message: find_translation(:invalid_user) },
34
- REPEATED_USER: { code: 3, message: find_translation(:duplicated_emails) },
35
- UNAUTHORIZED: { code: 4, message: find_translation(:unauthorized_user) },
36
- NOT_ALLOWED: { code: 5, message: find_translation(:standard_error) },
37
- BASE_ERROR: { code: 6, message: "" },
32
+ UNKNOWN_ERROR: { code: 6, message: find_translation(:standard_error) },
38
33
  ACTION_NOT_PERMITTED: { code: 7, message: find_translation(:action_not_permitted) },
39
- INVALID_DATE_RANGE: { code: 8, message: find_translation(:invalid_date_range) },
40
- AUTHENTICATION_FAILURE: { code: 9, message: find_translation(:authentication_failure) },
41
34
  }
42
35
  end
43
36
 
@@ -2,11 +2,7 @@ module ApiException
2
2
  class ControllerException < BaseException
3
3
 
4
4
  def initialize(error_type, errors, params, platform = "API")
5
- super(error_type, errors, params, platform)
6
-
7
- @error = error_code_map[error_type]
8
-
9
- define_attributes(error_type, errors, params, platform)
5
+ super
10
6
  end
11
7
 
12
8
  private
@@ -2,11 +2,7 @@ module ApiException
2
2
  class FileException < BaseException
3
3
 
4
4
  def initialize(error_type, errors, params, platform = "API")
5
- super(error_type, errors, params, platform)
6
-
7
- @error = error_code_map[error_type]
8
-
9
- define_attributes(error_type, errors, params, platform)
5
+ super
10
6
  end
11
7
 
12
8
  private
@@ -14,8 +10,8 @@ module ApiException
14
10
  # File error code should between 301 and 400
15
11
  def error_code_map
16
12
  {
17
- INVALID_FILE: { code: 301, message: find_translation(:empty_params) },
18
- UNSUPPORTED_FILE: { code: 302, message: find_translation(:invalid_params) },
13
+ INVALID_FILE: { code: 301, message: find_translation(:invalid_file) },
14
+ UNSUPPORTED_FILE: { code: 302, message: find_translation(:unsupported_file) },
19
15
  INVALID_EXTENSION: { code: 303, message: find_translation(:invalid_extension)},
20
16
  CANT_DECODE: { code: 304, message: find_translation(:cant_decode)},
21
17
  MAX_SIZE_EXCEEDEED: { code: 305, message: find_translation(:max_size_exceeded)},
@@ -2,11 +2,7 @@ module ApiException
2
2
  class ModelException < BaseException
3
3
 
4
4
  def initialize(error_type, errors, params, platform = "API")
5
- super(error_type, errors, params, platform)
6
-
7
- @error = error_code_map[error_type]
8
-
9
- define_attributes(error_type, errors, params, platform)
5
+ super
10
6
  end
11
7
 
12
8
  private
@@ -0,0 +1,30 @@
1
+ module ApiException
2
+ class RequestException < BaseException
3
+
4
+ def initialize(error_type, errors, params, platform = "API")
5
+ super
6
+ end
7
+
8
+ private
9
+
10
+ # File error code should between 401 and 500
11
+ def error_code_map
12
+ {
13
+ TIMEOUT: { code: 401, message: find_translation(:timeout) },
14
+ REQUEST_FORMAT_ERROR: { code: 402, message: find_translation(:request_format_error) },
15
+ INVALID_RESPONSE: { code: 403, message: find_translation(:invalid_response)},
16
+ REQUEST_SERVER_ERROR: { code: 404, message: find_translation(:request_sever_error)},
17
+ CONNECTION_REFUSED: { code: 405, message: find_translation(:connection_refused)},
18
+ HTTP_ERROR_CODE: { code: 406, message: find_translation(:http_error_code)},
19
+ ENCODING_ERROR: { code: 407, message: find_translation(:encoding_error)},
20
+ SSL_ERROR: { code: 408, message: find_translation(:ssl_error)},
21
+ DNS_ERROR: { code: 409, message: find_translation(:dns_error)},
22
+ AUTHENTICATION_ERROR: { code: 410, message: find_translation(:authentication_error)},
23
+ }
24
+ end
25
+
26
+ def find_translation(error)
27
+ I18n.t("request_exceptions.#{error.to_s}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module ApiException
2
+ class UserException < BaseException
3
+
4
+ def initialize(error_type, errors, params, platform = "API")
5
+ super
6
+ end
7
+
8
+ private
9
+
10
+ # User error code should between 501 and 600
11
+ def error_code_map
12
+ {
13
+ DUPLICATED_USER: { code: 501, message: find_translation(:duplicated_user) },
14
+ AUTHENTICATION_ERROR: { code: 502, message: find_translation(:authentication_error) },
15
+ PERMISSION_DENIED: { code: 503, message: find_translation(:permission_denied) },
16
+ INSECURE_PASSWORD_STORAGE: { code: 504, message: find_translation(:insecure_password_storage) },
17
+ PROFILE_UPDATE_ERROR: { code: 505, message: find_translation(:profile_update_error) },
18
+ }
19
+ end
20
+
21
+ def find_translation(error)
22
+ I18n.t("user_exceptions.#{error.to_s}")
23
+ end
24
+ end
25
+ end
@@ -2,5 +2,5 @@ module ApiException
2
2
  # first number stable version
3
3
  # second number major release
4
4
  # bug fixes or minor release
5
- VERSION = "1.1.1"
5
+ VERSION = "1.1.2"
6
6
  end
data/lib/api_exception.rb CHANGED
@@ -6,6 +6,8 @@ require_relative 'api_exception/base_exception'
6
6
  require_relative 'api_exception/model_exception'
7
7
  require_relative 'api_exception/controller_exception'
8
8
  require_relative 'api_exception/file_exception'
9
+ require_relative 'api_exception/request_exception'
10
+ require_relative 'api_exception/user_exception'
9
11
 
10
12
  module ApiException
11
13
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_exception
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - killjoy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-17 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -43,6 +43,8 @@ files:
43
43
  - lib/api_exception/engine.rb
44
44
  - lib/api_exception/file_exception.rb
45
45
  - lib/api_exception/model_exception.rb
46
+ - lib/api_exception/request_exception.rb
47
+ - lib/api_exception/user_exception.rb
46
48
  - lib/api_exception/version.rb
47
49
  homepage: https://gitlab.com/code-nest2/api_exception
48
50
  licenses:
@@ -51,7 +53,7 @@ metadata:
51
53
  homepage_uri: https://gitlab.com/code-nest2/api_exception
52
54
  source_code_uri: https://gitlab.com/code-nest2/api_exception
53
55
  changelog_uri: https://gitlab.com/code-nest2/api_exception/-/blob/main/README.md?ref_type=heads
54
- post_install_message:
56
+ post_install_message:
55
57
  rdoc_options: []
56
58
  require_paths:
57
59
  - lib
@@ -66,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  - !ruby/object:Gem::Version
67
69
  version: '0'
68
70
  requirements: []
69
- rubygems_version: 3.5.21
70
- signing_key:
71
+ rubygems_version: 3.5.6
72
+ signing_key:
71
73
  specification_version: 4
72
74
  summary: Simple Exception handle
73
75
  test_files: []