Skip to content

Commit eab25c3

Browse files
authored
Merge pull request #710 from code0-tech/fix-old-error-code-usage
Fix old usage of error_code
2 parents 625a103 + f9ac51d commit eab25c3

8 files changed

Lines changed: 42 additions & 17 deletions

File tree

app/services/error_code.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def self.validate_error_code!(error_code)
1010
raise InvalidErrorCode, error_code unless error_codes.include?(error_code)
1111
end
1212

13+
# rubocop:disable Layout/LineLength -- To keep readability of the error codes
1314
def self.error_codes
1415
{
1516
missing_permission: { description: 'The user is not permitted to perform this operation' },
@@ -69,15 +70,26 @@ def self.error_codes
6970
license_not_found: { description: 'The namespace license with the given identifier was not found' },
7071
flow_type_not_found: { description: 'The flow type with the given identifier was not found' },
7172
organization_not_found: { description: 'The organization with the given identifier was not found' },
73+
invalid_runtime_function_id: { description: 'The runtime function ID is invalid' },
74+
invalid_runtime_parameter_id: { description: 'The runtime parameter ID is invalid' },
75+
referenced_value_not_found: { description: 'A referenced value could not be found' },
76+
invalid_runtime_parameter_definition: { description: 'The runtime parameter definition is invalid' },
77+
invalid_runtime_function_definition: { description: 'The runtime function definition is invalid' },
78+
no_generic_type_for_identifier: { description: 'No generic type could be found for the given identifier' },
79+
no_data_type_for_identifier: { description: 'No data type could be found for the given identifier' },
80+
no_datatype_identifier_for_generic_key: { description: 'No data type identifier could be found for the given generic key' },
81+
invalid_generic_mapper: { description: 'The generic mapper is invalid because of active model errors' },
82+
invalid_data_type: { description: 'The data type is invalid because of active model errors' },
83+
7284
primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
7385
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
7486
tertiary_level_exceeds_parameters: { description: '', deprecation_reason: 'Outdated concept' },
75-
7687
missing_primary_runtime: { description: 'The project is missing a primary runtime' },
7788
missing_definition: { description: 'The primary runtime has more definitions than this one' },
7889
outdated_definition: { description: 'The primary runtime has a newer definition than this one' },
7990
}
8091
end
92+
# rubocop:enable Layout/LineLength
8193
end
8294

8395
ErrorCode.prepend_extensions

app/services/namespaces/projects/flows/create_service.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def execute
4949
unless flow.persisted?
5050
t.rollback_and_return! ServiceResponse.error(
5151
message: 'Failed to create flow',
52-
payload: flow.errors
52+
error_code: :invalid_flow,
53+
details: flow.errors
5354
)
5455
end
5556

@@ -58,7 +59,8 @@ def execute
5859
if res.error?
5960
t.rollback_and_return! ServiceResponse.error(
6061
message: 'Flow validation failed',
61-
payload: res.payload
62+
error_code: :flow_validation_failed,
63+
details: res.payload
6264
)
6365
end
6466

@@ -85,7 +87,7 @@ def create_node_function(node_function_id, input_nodes, t)
8587
if runtime_function_definition.nil?
8688
t.rollback_and_return! ServiceResponse.error(
8789
message: 'Invalid runtime function id',
88-
payload: :invalid_runtime_function_id
90+
error_code: :invalid_runtime_function_id
8991
)
9092
end
9193

@@ -95,7 +97,7 @@ def create_node_function(node_function_id, input_nodes, t)
9597
if runtime_parameter.nil?
9698
t.rollback_and_return! ServiceResponse.error(
9799
message: 'Invalid runtime parameter id',
98-
payload: :invalid_runtime_parameter_id
100+
error_code: :invalid_runtime_parameter_id
99101
)
100102
end
101103

@@ -121,7 +123,7 @@ def create_node_function(node_function_id, input_nodes, t)
121123
if reference_value.nil?
122124
t.rollback_and_return! ServiceResponse.error(
123125
message: 'Referenced node function not found',
124-
payload: :referenced_value_not_found
126+
error_code: :referenced_value_not_found
125127
)
126128
end
127129

app/services/runtimes/data_types/update_service.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def execute
2020
sort_data_types(data_types).each do |data_type|
2121
unless update_datatype(data_type, t)
2222
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
23-
payload: data_type.errors)
23+
error_code: :invalid_data_type, details: data_type.errors)
2424
end
2525
end
2626

@@ -104,7 +104,7 @@ def find_data_type_identifier(parent_type_rule_config, t)
104104
if generic_type.nil?
105105
t.rollback_and_return! ServiceResponse.error(
106106
message: "Could not find generic type with identifier #{identifier.generic_type.data_type_identifier}",
107-
payload: :no_generic_type_for_identifier
107+
error_code: :no_generic_type_for_identifier
108108
)
109109
end
110110

@@ -127,7 +127,7 @@ def create_data_type_identifier(t, **kwargs)
127127
if data_type_identifier.nil?
128128
t.rollback_and_return! ServiceResponse.error(
129129
message: "Could not find datatype identifier with #{kwargs}",
130-
payload: :no_datatype_identifier_for_generic_key
130+
error_code: :no_datatype_identifier_for_generic_key
131131
)
132132
end
133133

@@ -139,7 +139,7 @@ def find_data_type(identifier, t)
139139

140140
if data_type.nil?
141141
t.rollback_and_return! ServiceResponse.error(message: "Could not find datatype with identifier #{identifier}",
142-
payload: :no_datatype_for_identifier)
142+
error_code: :no_data_type_for_identifier)
143143
end
144144

145145
data_type

app/services/runtimes/flow_types/update_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def find_datatype(identifier, t)
5656

5757
if data_type.nil?
5858
t.rollback_and_return! ServiceResponse.error(message: "Could not find datatype with identifier #{identifier}",
59-
payload: :no_datatype_for_identifier)
59+
error_code: :no_data_type_for_identifier)
6060
end
6161

6262
data_type

app/services/runtimes/runtime_function_definitions/update_service.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def update_mappers(generic_mappers, t)
9292
if mapper.nil? || !mapper.save
9393
t.rollback_and_return! ServiceResponse.error(
9494
message: "Could not find or create generic mapper (#{generic_mapper})",
95-
payload: :error_creating_generic_mapper
95+
error_code: :invalid_generic_mapper
9696
)
9797
end
9898
mapper
@@ -120,7 +120,7 @@ def find_data_type_identifier(identifier, t)
120120
if generic_type.nil?
121121
t.rollback_and_return! ServiceResponse.error(
122122
message: "Could not find generic type with identifier #{identifier.generic_type.data_type_identifier}",
123-
payload: :no_generic_type_for_identifier
123+
error_code: :no_generic_type_for_identifier
124124
)
125125
end
126126

@@ -143,7 +143,7 @@ def create_data_type_identifier(t, **kwargs)
143143
if data_type_identifier.nil?
144144
t.rollback_and_return! ServiceResponse.error(
145145
message: "Could not find datatype identifier with #{kwargs}",
146-
payload: :no_datatype_identifier_for_generic_key
146+
error_code: :no_datatype_identifier_for_generic_key
147147
)
148148
end
149149

@@ -186,7 +186,8 @@ def update_parameters(runtime_function_definition, parameters, db_parameters, t)
186186
unless db_param.save
187187
t.rollback_and_return! ServiceResponse.error(
188188
message: 'Could not save runtime parameter definition',
189-
payload: db_param.errors
189+
error_code: :invalid_runtime_parameter_definition,
190+
details: db_param.errors
190191
)
191192
end
192193

app/services/users/identity/unlink_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize(current_authentication, identity)
1616
def execute
1717
transactional do |t|
1818
if identity.nil?
19-
t.rollback_and_return! ServiceResponse.error(payload: :external_identity_does_not_exist,
19+
t.rollback_and_return! ServiceResponse.error(error_code: :external_identity_does_not_exist,
2020
message: 'Nil identity given')
2121
end
2222

app/services/users/mfa/backup_codes/rotate_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def generate_new_codes(t)
4949
user: current_user)).persisted?
5050
if i > 10
5151
t.rollback_and_return! ServiceResponse.error(message: 'Failed to save valid backup code',
52-
payload: :failed_to_save_valid_backup_code)
52+
error_code: :failed_to_save_valid_backup_code)
5353
end
5454
i += 1
5555
end

docs/graphql/enum/errorcodeenum.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ Represents the available error responses
2424
| `IDENTITY_VALIDATION_FAILED` | Failed to validate the external identity |
2525
| `INCONSISTENT_NAMESPACE` | Resources are from different namespaces |
2626
| `INVALID_ATTACHMENT` | The attachment is invalid because of active model errors |
27+
| `INVALID_DATA_TYPE` | The data type is invalid because of active model errors |
2728
| `INVALID_EXTERNAL_IDENTITY` | This external identity is invalid |
2829
| `INVALID_FLOW` | The flow is invalid because of active model errors |
2930
| `INVALID_FLOW_SETTING` | The flow setting is invalid because of active model errors |
31+
| `INVALID_GENERIC_MAPPER` | The generic mapper is invalid because of active model errors |
3032
| `INVALID_LOGIN_DATA` | Invalid login data provided |
3133
| `INVALID_NAMESPACE_LICENSE` | The namespace license is invalid because of active model errors |
3234
| `INVALID_NAMESPACE_MEMBER` | The namespace member is invalid because of active model errors |
@@ -35,6 +37,10 @@ Represents the available error responses
3537
| `INVALID_ORGANIZATION` | The organization is invalid because of active model errors |
3638
| `INVALID_PASSWORD_REPEAT` | The provided password repeat does not match the password |
3739
| `INVALID_RUNTIME` | The runtime is invalid because of active model errors |
40+
| `INVALID_RUNTIME_FUNCTION_DEFINITION` | The runtime function definition is invalid |
41+
| `INVALID_RUNTIME_FUNCTION_ID` | The runtime function ID is invalid |
42+
| `INVALID_RUNTIME_PARAMETER_DEFINITION` | The runtime parameter definition is invalid |
43+
| `INVALID_RUNTIME_PARAMETER_ID` | The runtime parameter ID is invalid |
3844
| `INVALID_SETTING` | Invalid setting provided |
3945
| `INVALID_TOTP_SECRET` | The TOTP secret is invalid or cannot be verified |
4046
| `INVALID_USER` | The user is invalid because of active model errors |
@@ -54,12 +60,16 @@ Represents the available error responses
5460
| `NAMESPACE_NOT_FOUND` | The namespace with the given identifier was not found |
5561
| `NAMESPACE_PROJECT_NOT_FOUND` | The namespace project with the given identifier was not found |
5662
| `NAMESPACE_ROLE_NOT_FOUND` | The namespace role with the given identifier was not found |
63+
| `NO_DATATYPE_IDENTIFIER_FOR_GENERIC_KEY` | No data type identifier could be found for the given generic key |
64+
| `NO_DATA_TYPE_FOR_IDENTIFIER` | No data type could be found for the given identifier |
5765
| `NO_FREE_LICENSE_SEATS` | There are no free license seats to complete this operation |
66+
| `NO_GENERIC_TYPE_FOR_IDENTIFIER` | No generic type could be found for the given identifier |
5867
| `NO_PRIMARY_RUNTIME` | The project does not have a primary runtime |
5968
| `ORGANIZATION_NOT_FOUND` | The organization with the given identifier was not found |
6069
| `OUTDATED_DEFINITION` | The primary runtime has a newer definition than this one |
6170
| `PRIMARY_LEVEL_NOT_FOUND` | **Deprecated:** Outdated concept |
6271
| `PROJECT_NOT_FOUND` | The namespace project with the given identifier was not found |
72+
| `REFERENCED_VALUE_NOT_FOUND` | A referenced value could not be found |
6373
| `REGISTRATION_DISABLED` | Self-registration is disabled |
6474
| `RUNTIME_MISMATCH` | Resources are from different runtimes |
6575
| `RUNTIME_NOT_FOUND` | The runtime with the given identifier was not found |

0 commit comments

Comments
 (0)