api_exception 1.0.0 → 1.1.0

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: 470b587029958c92a73e72c11fa665682f6075b0a837a52458119c103b905f28
4
- data.tar.gz: 1f397f8fb83fc90ee8b43c3ca5ce8ee305e4571d7676d5af543c786b7f2a7ec4
3
+ metadata.gz: 31dae7bf907380e156ff2739d9c380858146e6202923c29c9cc092240ffaf754
4
+ data.tar.gz: 03b08162c084c846b1844b17e5d21103759f6ffc7557f2136418d634edba74d7
5
5
  SHA512:
6
- metadata.gz: 84588aebe63e702c03e127788d129e6105afd34c93f47648ee1223658399b85534892f43e08e427c899b1491395201981988247e2ce386f3a9c111d33e58ec75
7
- data.tar.gz: b6d62c6f8b18bc816ef02063888a4f268093c088d2b95d7b98eb03b50c198f8f3b821a89d5d1f095b77d7c413021f43e8f7850ecfeb6a9f7e804505774cb749c
6
+ metadata.gz: 0b3a56f7b1df66be42077498dd68857b2f04c4acdafa75de1762a2b7ded78639fcbbb85fd92e034bed2121e1f7f9f23204204e1a68a8b7dd52a167593d7c0438
7
+ data.tar.gz: b0ca4ff6e4221e0213782cf7330e2514bfe5adb3c8a137362da708f2948f424e5e7e81b0f83f0dae9782917fce8dfb71eef07340a97a6a47e819ca8834b6bd7d
@@ -1,18 +1,30 @@
1
1
  en:
2
2
  base_exceptions:
3
- record_not_found: "Record not found for %{model}"
4
3
  timeout: "Could not connect to %{provider}"
5
4
  invalid_user: Invalid user
6
5
  duplicated_emails: Some user emails are duplicated
7
- invalid_status_change: "Cannot change status from %{original_status} to %{new_status}"
8
6
  unauthorized_user: User is unauthorized to do this action
9
7
  standard_error: "%{message}"
10
- cannot_update: "Cannot update %{model} with the requested parameters"
11
- not_unique_record: ID should be unique for this datatype
12
8
  action_not_permitted: Action is not permitted
9
+ invalid_date_range: Invalid date range
10
+ authentication_failure: Verify authentication parameters.
11
+ model_exceptions:
12
+ record_not_found: "Record not found for %{model}"
13
+ invalid_status_change: "Cannot change status from %{original_status} to %{new_status}"
14
+ invalid_update: "Cannot update %{model} with the requested parameters"
15
+ not_unique_record: ID should be unique for this datatype
16
+ 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.
18
+ unique_combination: There is a unique combination of attributes already in use
19
+ required_dependency_missing: "%{model} depends of %{dependency_model} relation before save"
20
+ validation_failed: There are some validation failed, before save this record ensure to pass them
21
+ controller_exceptions:
22
+ empty_params: The provided params are empty
23
+ invalid_params: The provided params are invalid
24
+ file_exceptions:
13
25
  invalid_file: One or more of the sent file are invalid or corrupt
14
26
  unsupported_file: The file you are trying to upload is not supported
15
- invalid_params: There was a problem in the JSON submitted
16
- update_conflict: Update conflict. Please retry.
17
- invalid_date_range: Invalid date range
18
- authentication_failure: Verify authentication parameters.
27
+ invalid_extension: "The file has an invalid extension, allowed extensions are: %{extension_allowed}"
28
+ cant_decode: The file could not be decoded
29
+ max_size_exceeded: "The file exceeds the maximum defined size: %{max_size}"
30
+ invalid_content: The file does not have valid content
@@ -1,18 +1,30 @@
1
1
  es:
2
2
  base_exceptions:
3
- record_not_found: "Registro no encontrado para %{model}"
4
3
  timeout: "No se pudo conectar a %{provider}"
5
4
  invalid_user: Usuario invalido
6
5
  duplicated_emails: Algunos e-mails están duplicados
7
- invalid_status_change: "No se puede cambiar el status de %{original_status} a %{new_status}"
8
6
  unauthorized_user: Usuario no autorizado para realizar esta acción
9
7
  standard_error: "%{message}"
10
- cannot_update: "No se puede actualizar %{model} con los estos parametros"
11
- not_unique_record: El identificador debe ser único para este tipo de dato
12
8
  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
+ model_exceptions:
12
+ record_not_found: "Registro no encontrado para %{model}"
13
+ invalid_status_change: "No se puede cambiar el status de %{original_status} a %{new_status}"
14
+ invalid_update: "No se puede actualizar %{model} con los parametros proporcionados"
15
+ not_unique_record: El identificador debe ser único para este tipo de dato
16
+ invalid_attributes: "Algunos atributos proporcionados no son válidos o no están permitidos para el modelo %{model}"
17
+ update_conflict: Conflicto de actualización. Por favor revise los atributos e intenta nuevamente.
18
+ unique_combination: Existe una combinación única de atributos que ya se encuentra en uso
19
+ required_dependency_missing: "%{model} depende de tener una relacion con %{dependency_model} antes de guardar el registro"
20
+ validation_failed: Hay algunas validaciones fallidas, antes de guardar este registro asegúrese de cumplirlas
21
+ controller_exceptions:
22
+ empty_params: Los parámetros proporcionados se encuentran vacios
23
+ invalid_params: Los parámetros proporcionados son inválidos
24
+ file_exceptions:
13
25
  invalid_file: Uno o más de los archivos que se están enviando son inválidos o están corruptos
14
26
  unsupported_file: El archivo que está intentando cargar no está soportado
15
- invalid_params: Hubo un problema con el JSON enviado
16
- update_conflict: Conflicto de actualización. Por favor, intenta nuevamente.
17
- invalid_date_range: Rango de fechas inválido
18
- authentication_failure: Verifique parámetros de autenticación.
27
+ invalid_extension: "El archivo tiene una extension invalida, las extensiones permitidas son: %{extension_allowed}"
28
+ cant_decode: El archivo no pudo ser decodificado
29
+ max_size_exceeded: "El archivo excede el tamaño maximo definido de %{max_size}"
30
+ invalid_content: El archivo no tiene un contenido valido
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module ApiException
4
2
  class BaseException < StandardError
5
3
  include ActiveModel::Model
@@ -8,17 +6,9 @@ module ApiException
8
6
  attr_reader :code, :message, :errors, :type, :error_type
9
7
 
10
8
  def initialize(error_type, errors, params, platform = "API")
11
- error = error_code_map[error_type]
12
- @hash_message = error[:message]
13
- @params = params
9
+ @error = error_code_map[error_type]
14
10
 
15
- @error_type = error_type
16
- @errors = [*errors]
17
- @code = error[:code] if error
18
- @message = parse_message if error
19
- @errors.push(@message)
20
- @errors = @errors.flatten
21
- @type = platform
11
+ define_attributes(error_type, errors, params, platform)
22
12
  end
23
13
 
24
14
  def parse_message
@@ -36,25 +26,18 @@ module ApiException
36
26
 
37
27
  private
38
28
 
29
+ # Base error code should between 1 and 100
39
30
  def error_code_map
40
31
  {
41
32
  TIMEOUT: { code: 1, message: find_translation(:timeout) },
42
- RECORD_NOT_FOUND: { code: 2, message: find_translation(:record_not_found) },
43
- INVALID_USER: { code: 3, message: find_translation(:invalid_user) },
44
- REPEATED_USER: { code: 4, message: find_translation(:duplicated_emails) },
45
- INVALID_STATUS_CHANGE: { code: 5, message: find_translation(:invalid_status_change) },
46
- UNAUTHORIZED: { code: 6, message: find_translation(:unauthorized_user) },
47
- NOT_ALLOWED: { code: 7, message: find_translation(:standard_error) },
48
- INVALID_UPDATE: { code: 8, message: find_translation(:cannot_update) },
49
- BASE_ERROR: { code: 9, message: "" },
50
- NOT_UNIQUE_RECORD: { code: 10, message: find_translation(:not_unique_record) },
51
- ACTION_NOT_PERMITTED: { code: 11, message: find_translation(:action_not_permitted) },
52
- INVALID_FILE: { code: 12, message: find_translation(:invalid_file) },
53
- UNSUPPORTED_FILE: { code: 13, message: find_translation(:unsupported_file) },
54
- INVALID_PARAMS: { code: 14, message: find_translation(:invalid_params) },
55
- UPDATE_CONFLICT: { code: 15, message: find_translation(:update_conflict) },
56
- INVALID_DATE_RANGE: { code: 16, message: find_translation(:invalid_date_range) },
57
- AUTHENTICATION_FAILURE: { code: 17, message: find_translation(:authentication_failure) },
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: "" },
38
+ 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) },
58
41
  }
59
42
  end
60
43
 
@@ -69,5 +52,18 @@ module ApiException
69
52
  def find_translation(error)
70
53
  I18n.t("base_exceptions.#{error.to_s}")
71
54
  end
55
+
56
+ def define_attributes(error_type, errors, params, platform)
57
+ @hash_message = @error[:message]
58
+ @params = params
59
+
60
+ @error_type = error_type
61
+ @errors = [*errors]
62
+ @code = @error[:code] if @error
63
+ @message = parse_message if @error
64
+ @errors.push(@message)
65
+ @errors = @errors.flatten
66
+ @type = platform
67
+ end
72
68
  end
73
69
  end
@@ -0,0 +1,26 @@
1
+ module ApiException
2
+ class ControllerException < BaseException
3
+
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)
10
+ end
11
+
12
+ private
13
+
14
+ # Controller error code should between 201 and 300
15
+ def error_code_map
16
+ {
17
+ EMPTY_PARAMS: { code: 201, message: find_translation(:empty_params) },
18
+ INVALID_PARAMS: { code: 202, message: find_translation(:invalid_params) },
19
+ }
20
+ end
21
+
22
+ def find_translation(error)
23
+ I18n.t("controller_exceptions.#{error.to_s}")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module ApiException
2
+ class FileException < BaseException
3
+
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)
10
+ end
11
+
12
+ private
13
+
14
+ # File error code should between 301 and 400
15
+ def error_code_map
16
+ {
17
+ INVALID_FILE: { code: 301, message: find_translation(:empty_params) },
18
+ UNSUPPORTED_FILE: { code: 302, message: find_translation(:invalid_params) },
19
+ INVALID_EXTENSION: { code: 303, message: find_translation(:invalid_extension)},
20
+ CANT_DECODE: { code: 304, message: find_translation(:cant_decode)},
21
+ MAX_SIZE_EXCEEDEED: { code: 305, message: find_translation(:max_size_exceeded)},
22
+ INVALID_CONTENT: { code: 306, message: find_translation(:invalid_content)},
23
+ }
24
+ end
25
+
26
+ def find_translation(error)
27
+ I18n.t("file_exceptions.#{error.to_s}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module ApiException
2
+ class ModelException < BaseException
3
+
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)
10
+ end
11
+
12
+ private
13
+
14
+ # Model error code should between 101 and 200
15
+ def error_code_map
16
+ {
17
+ RECORD_NOT_FOUND: { code: 101, message: find_translation(:record_not_found) },
18
+ INVALID_STATUS_CHANGE: { code: 102, message: find_translation(:invalid_status_change) },
19
+ INVALID_UPDATE: { code: 103, message: find_translation(:invalid_update) },
20
+ NOT_UNIQUE_RECORD: { code: 104, message: find_translation(:not_unique_record) },
21
+ INVALID_ATTRIBUTES: { code: 105, message: find_translation(:invalid_attributes) },
22
+ UPDATE_CONFLICT: { code: 106, message: find_translation(:update_conflict) },
23
+ UNIQUE_COMBINATION: { code: 107, message: find_translation(:unique_combination) },
24
+ REQUIRED_DEPENDENCY_MISSING: { code: 108, message: find_translation(:required_dependency_missing) },
25
+ VALIDATION_FAILED: { code: 109, message: find_translation(:validation_failed) },
26
+ }
27
+ end
28
+
29
+ def find_translation(error)
30
+ I18n.t("model_exceptions.#{error.to_s}")
31
+ end
32
+ end
33
+ end
@@ -2,5 +2,5 @@ module ApiException
2
2
  # first number stable version
3
3
  # second number major release
4
4
  # bug fixes
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
data/lib/api_exception.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require "api_exception/version"
2
2
  require "api_exception/engine"
3
+
4
+ # Personalized Exceptions
3
5
  require_relative 'api_exception/base_exception'
6
+ require_relative 'api_exception/model_exception'
7
+ require_relative 'api_exception/controller_exception'
8
+ require_relative 'api_exception/file_exception'
4
9
 
5
10
  module ApiException
6
11
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_exception
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - killjoy
@@ -48,7 +48,10 @@ files:
48
48
  - config/routes.rb
49
49
  - lib/api_exception.rb
50
50
  - lib/api_exception/base_exception.rb
51
+ - lib/api_exception/controller_exception.rb
51
52
  - lib/api_exception/engine.rb
53
+ - lib/api_exception/file_exception.rb
54
+ - lib/api_exception/model_exception.rb
52
55
  - lib/api_exception/version.rb
53
56
  - lib/tasks/api_exception_tasks.rake
54
57
  homepage: https://gitlab.com/code-nest2/api_exception