api_exception 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 470b587029958c92a73e72c11fa665682f6075b0a837a52458119c103b905f28
4
- data.tar.gz: 1f397f8fb83fc90ee8b43c3ca5ce8ee305e4571d7676d5af543c786b7f2a7ec4
3
+ metadata.gz: 8b90703e1bb43fa3822e44d1b51e37a8a9ac66ba6229351e40eeffe7bee4020a
4
+ data.tar.gz: 4f806eabfe86079a1dd7882d37c0c3c5fea70e7bb642ed6f628f30bad57c2c0f
5
5
  SHA512:
6
- metadata.gz: 84588aebe63e702c03e127788d129e6105afd34c93f47648ee1223658399b85534892f43e08e427c899b1491395201981988247e2ce386f3a9c111d33e58ec75
7
- data.tar.gz: b6d62c6f8b18bc816ef02063888a4f268093c088d2b95d7b98eb03b50c198f8f3b821a89d5d1f095b77d7c413021f43e8f7850ecfeb6a9f7e804505774cb749c
6
+ metadata.gz: cec3705d7c5049d5a8108743905f8bc44b4441509ab1603a00356194b7035ca5bfea2e0e07e72d0daa3776be64e6d553ad3ef56facadfde3fc40ac446483f0f5
7
+ data.tar.gz: d03479ab02b272b25c26b54f4a840ef572ec91aff4123f4b7aec5057edbbf0b37568b6ab355ff7fa3df241618845f43fa658eb31d4d3c801c35b43b242e4b1ab
@@ -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
@@ -1,6 +1,6 @@
1
1
  module ApiException
2
2
  # first number stable version
3
3
  # second number major release
4
- # bug fixes
5
- VERSION = "1.0.0"
4
+ # bug fixes or minor release
5
+ VERSION = "1.1.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - killjoy
@@ -35,22 +35,15 @@ files:
35
35
  - MIT-LICENSE
36
36
  - README.md
37
37
  - Rakefile
38
- - app/assets/config/api_exception_manifest.js
39
- - app/assets/stylesheets/api_exception/application.css
40
- - app/controllers/api_exception/application_controller.rb
41
- - app/helpers/api_exception/application_helper.rb
42
- - app/jobs/api_exception/application_job.rb
43
- - app/mailers/api_exception/application_mailer.rb
44
- - app/models/api_exception/application_record.rb
45
- - app/views/layouts/api_exception/application.html.erb
46
38
  - config/locales/en/en.yml
47
39
  - config/locales/es/es.yml
48
- - config/routes.rb
49
40
  - lib/api_exception.rb
50
41
  - lib/api_exception/base_exception.rb
42
+ - lib/api_exception/controller_exception.rb
51
43
  - lib/api_exception/engine.rb
44
+ - lib/api_exception/file_exception.rb
45
+ - lib/api_exception/model_exception.rb
52
46
  - lib/api_exception/version.rb
53
- - lib/tasks/api_exception_tasks.rake
54
47
  homepage: https://gitlab.com/code-nest2/api_exception
55
48
  licenses:
56
49
  - MIT
@@ -66,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
59
  requirements:
67
60
  - - ">="
68
61
  - !ruby/object:Gem::Version
69
- version: '0'
62
+ version: 3.3.0
70
63
  required_rubygems_version: !ruby/object:Gem::Requirement
71
64
  requirements:
72
65
  - - ">="
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/api_exception .css
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,4 +0,0 @@
1
- module ApiException
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module ApiException
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module ApiException
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module ApiException
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: "from@example.com"
4
- layout "mailer"
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module ApiException
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Api exception</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= yield :head %>
9
-
10
- <%= stylesheet_link_tag "api_exception/application", media: "all" %>
11
- </head>
12
- <body>
13
-
14
- <%= yield %>
15
-
16
- </body>
17
- </html>
data/config/routes.rb DELETED
@@ -1,2 +0,0 @@
1
- ApiException::Engine.routes.draw do
2
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :api_exception do
3
- # # Task goes here
4
- # end