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 +4 -4
- data/README.md +22 -2
- data/config/locales/en/en.yml +10 -1
- data/config/locales/es/es.yml +9 -0
- data/lib/api_exception/base_exception.rb +1 -1
- data/lib/api_exception/controller_exception.rb +1 -1
- data/lib/api_exception/file_exception.rb +1 -1
- data/lib/api_exception/model_exception.rb +1 -1
- data/lib/api_exception/request_exception.rb +1 -1
- data/lib/api_exception/service_exception.rb +29 -0
- data/lib/api_exception/user_exception.rb +1 -1
- data/lib/api_exception/version.rb +1 -1
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27f04c16cb291109915c1ea4787587cc66fb40841121b4844c3c4dbd117b2582
|
|
4
|
+
data.tar.gz: 5996cc49ba242dbc5b7d316bceb61358efe72215660be16cbb47a11180787012
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/config/locales/en/en.yml
CHANGED
|
@@ -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
|
data/config/locales/es/es.yml
CHANGED
|
@@ -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)
|
|
@@ -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
|
+
|
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.
|
|
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:
|
|
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.
|
|
72
|
-
signing_key:
|
|
70
|
+
rubygems_version: 3.6.9
|
|
73
71
|
specification_version: 4
|
|
74
72
|
summary: Simple Exception handle
|
|
75
73
|
test_files: []
|