api_exception 1.1.2 → 1.2.3

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: 98dabbff847276d241f8b6339317135669ea5001b75d936bbc42fc9f001dbcde
4
- data.tar.gz: 5d1423c28d88c359b727c1de12b76ae593382d6155966644aae31cca6b6352e2
3
+ metadata.gz: 27f04c16cb291109915c1ea4787587cc66fb40841121b4844c3c4dbd117b2582
4
+ data.tar.gz: 5996cc49ba242dbc5b7d316bceb61358efe72215660be16cbb47a11180787012
5
5
  SHA512:
6
- metadata.gz: e9554a7292def309a58d54af58e6ad235069dbacd75a5c5c9ea494f55b89310e4e5a7ce610fe408e58795be5b6d656209139cdef1eb4c30fe202e4c1ed375540
7
- data.tar.gz: 7acb28722554c9864bc66154a8ad8a2fe7e655d9f75a0d1c4e4d83c3826aa1f39ec67f45858fd369c0f330cf21c0d5b45380f7ac45cc9339a8de5a1c8d6b8610
6
+ metadata.gz: 9302833bc0e8e1f5d820d75e624d79dce16f42c39eb9d71299f4a4753b6d52aefdb3ef5a536aa1673edf3635d32afdea6c3dc3997a3cfd1b821c7c483a63f45e
7
+ data.tar.gz: fa67d0509d5c19b635d54dd03fb11c136ca00a318d0f6b4856a8d2389e7973b21e1bd908884fb5a58b8081f953d8cf88ef6ad84bbb7300a9ca48877c9f3ce1db
data/README.md CHANGED
@@ -10,11 +10,31 @@ ApiException::BaseException
10
10
  # You can initialize with the following params
11
11
  # error_type -> This argument should be a symbol
12
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
13
+ # params -> Should be a hash as params for I18n.t translations (optional)
14
+ # platform -> Should specify where this error is rendered from, 'API' value is by default (optional)
15
15
  ApiException::BaseException.new(:UNKNOWN_ERROR, ["Something went wrong"], { process: "" })
16
16
  ```
17
17
 
18
+ ## Examples availables
19
+ ```ruby
20
+
21
+ ApiException::ModelException.new(:RECORD_NOT_FOUND, ["Item not found"], { model: "User"})
22
+ #=> Record not found for User (ApiException::ModelException)
23
+
24
+ ApiException::ControllerException.new(:INVALID_PARAMS, ["cant parse body params"])
25
+ #=> The provided params are invalid (ApiException::ControllerException)
26
+
27
+ ApiException::FileException.new(:UNSUPPORTED_FILE, ["wrong file extension"])
28
+ #=> The file you are trying to upload is not supported (ApiException::FileException)
29
+
30
+ ApiException::RequestException.new(:TIMEOUT, ["Server response time exceed"], { timeout: "3 mins"})
31
+ #=> The response timeout was exceeded: 3 mins (ApiException::RequestException)
32
+
33
+ ApiException::UserException.new(:DUPLICATED_USER, ["user data already exist"])
34
+ #=> Duplicate user (ApiException::UserException)
35
+
36
+ ```
37
+
18
38
  ## Installation
19
39
  Add this line to your application's Gemfile:
20
40
 
@@ -38,4 +38,13 @@ en:
38
38
  authentication_error: The user could not be authenticated
39
39
  permission_denied: The user does not have the permissions to perform this action
40
40
  insecure_password_storage: The password must be strong
41
- profile_update_error: The user data could not be updated
41
+ profile_update_error: The user data could not be updated
42
+ service_exceptions:
43
+ invalid_parameters: The parameters provided to the service are invalid
44
+ business_logic_error: Business logic error in the service
45
+ transaction_error: An error occurred during the service transaction
46
+ missing_required_parameter: A required parameter is missing to execute the service
47
+ service_execution_failed: Service execution failed
48
+ invalid_context: The provided context is not valid for this operation
49
+ dependency_error: Error in the dependencies required by the service
50
+ validation_error: Validation error in the service
@@ -39,3 +39,12 @@ es:
39
39
  permission_denied: El usuario no cuenta con los permisos para realizar esta acción
40
40
  insecure_password_storage: La contraseña debe ser segura
41
41
  profile_update_error: No fue posible actualizar los datos del usuario
42
+ service_exceptions:
43
+ invalid_parameters: Los parámetros proporcionados al servicio no son válidos
44
+ business_logic_error: Error en la lógica de negocio del servicio
45
+ transaction_error: Ocurrió un error durante la transacción del servicio
46
+ missing_required_parameter: Falta un parámetro requerido para ejecutar el servicio
47
+ service_execution_failed: La ejecución del servicio falló
48
+ invalid_context: El contexto proporcionado no es válido para esta operación
49
+ dependency_error: Error en las dependencias requeridas por el servicio
50
+ validation_error: Error de validación en el servicio
@@ -5,7 +5,7 @@ module ApiException
5
5
 
6
6
  attr_reader :code, :message, :errors, :type, :error_type
7
7
 
8
- def initialize(error_type, errors, params, platform = "API")
8
+ def initialize(error_type, errors, params = {}, platform = "API")
9
9
  @error = error_code_map[error_type]
10
10
 
11
11
  define_attributes(error_type, errors, params, platform)
@@ -1,7 +1,7 @@
1
1
  module ApiException
2
2
  class ControllerException < BaseException
3
3
 
4
- def initialize(error_type, errors, params, platform = "API")
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
5
  super
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module ApiException
2
2
  class FileException < BaseException
3
3
 
4
- def initialize(error_type, errors, params, platform = "API")
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
5
  super
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module ApiException
2
2
  class ModelException < BaseException
3
3
 
4
- def initialize(error_type, errors, params, platform = "API")
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
5
  super
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module ApiException
2
2
  class RequestException < BaseException
3
3
 
4
- def initialize(error_type, errors, params, platform = "API")
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
5
  super
6
6
  end
7
7
 
@@ -0,0 +1,29 @@
1
+ module ApiException
2
+ class ServiceException < BaseException
3
+
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
+ super
6
+ end
7
+
8
+ private
9
+
10
+ # Service error code should between 601 and 700
11
+ def error_code_map
12
+ {
13
+ INVALID_PARAMETERS: { code: 601, message: find_translation(:invalid_parameters) },
14
+ BUSINESS_LOGIC_ERROR: { code: 602, message: find_translation(:business_logic_error) },
15
+ TRANSACTION_ERROR: { code: 603, message: find_translation(:transaction_error) },
16
+ MISSING_REQUIRED_PARAMETER: { code: 604, message: find_translation(:missing_required_parameter) },
17
+ SERVICE_EXECUTION_FAILED: { code: 605, message: find_translation(:service_execution_failed) },
18
+ INVALID_CONTEXT: { code: 606, message: find_translation(:invalid_context) },
19
+ DEPENDENCY_ERROR: { code: 607, message: find_translation(:dependency_error) },
20
+ VALIDATION_ERROR: { code: 608, message: find_translation(:validation_error) },
21
+ }
22
+ end
23
+
24
+ def find_translation(error)
25
+ I18n.t("service_exceptions.#{error.to_s}")
26
+ end
27
+ end
28
+ end
29
+
@@ -1,7 +1,7 @@
1
1
  module ApiException
2
2
  class UserException < BaseException
3
3
 
4
- def initialize(error_type, errors, params, platform = "API")
4
+ def initialize(error_type, errors, params = {}, platform = "API")
5
5
  super
6
6
  end
7
7
 
@@ -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.2"
5
+ VERSION = "1.2.3"
6
6
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_exception
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - killjoy
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -44,6 +43,7 @@ files:
44
43
  - lib/api_exception/file_exception.rb
45
44
  - lib/api_exception/model_exception.rb
46
45
  - lib/api_exception/request_exception.rb
46
+ - lib/api_exception/service_exception.rb
47
47
  - lib/api_exception/user_exception.rb
48
48
  - lib/api_exception/version.rb
49
49
  homepage: https://gitlab.com/code-nest2/api_exception
@@ -53,7 +53,6 @@ metadata:
53
53
  homepage_uri: https://gitlab.com/code-nest2/api_exception
54
54
  source_code_uri: https://gitlab.com/code-nest2/api_exception
55
55
  changelog_uri: https://gitlab.com/code-nest2/api_exception/-/blob/main/README.md?ref_type=heads
56
- post_install_message:
57
56
  rdoc_options: []
58
57
  require_paths:
59
58
  - lib
@@ -68,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
67
  - !ruby/object:Gem::Version
69
68
  version: '0'
70
69
  requirements: []
71
- rubygems_version: 3.5.6
72
- signing_key:
70
+ rubygems_version: 3.6.9
73
71
  specification_version: 4
74
72
  summary: Simple Exception handle
75
73
  test_files: []