Skip to content

Commit 3e8c3de

Browse files
authored
Merge pull request #670 from code0-tech/646-adjust-mutation-error-responses
Adjust mutation error responses
2 parents beb9116 + 3d7479b commit 3e8c3de

File tree

183 files changed

+727
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+727
-417
lines changed

app/graphql/mutations/base_mutation.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ def current_authentication
2626
context[:current_authentication]
2727
end
2828

29-
def create_message_error(message)
30-
Sagittarius::Graphql::ErrorMessageContainer.new(message: message)
29+
def create_error(code, message)
30+
ErrorCode.validate_error_code!(code)
31+
32+
Sagittarius::Graphql::ErrorContainer.new(
33+
code,
34+
[{ message: message }]
35+
)
3136
end
3237
end
3338
end

app/graphql/mutations/namespaces/members/assign_roles.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ def resolve(member_id:, role_ids:)
1818
member = SagittariusSchema.object_from_id(member_id)
1919
roles = role_ids.map { |id| SagittariusSchema.object_from_id(id) }
2020

21-
return { namespace_member_roles: nil, errors: [create_message_error('Invalid member')] } if member.nil?
22-
return { namespace_member_roles: nil, errors: [create_message_error('Invalid role')] } if roles.any?(&:nil?)
21+
if member.nil?
22+
return { namespace_member_roles: nil,
23+
errors: [create_error(:namespace_member_not_found, 'Invalid member')] }
24+
end
25+
if roles.any?(&:nil?)
26+
return { namespace_member_roles: nil,
27+
errors: [create_error(:namespace_role_not_found, 'Invalid role')] }
28+
end
2329

2430
::Namespaces::Members::AssignRolesService.new(
2531
current_authentication,

app/graphql/mutations/namespaces/members/delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def resolve(namespace_member_id:)
1616

1717
if namespace_member.nil?
1818
return { namespace_member: nil,
19-
errors: [create_message_error('Invalid member')] }
19+
errors: [create_error(:namespace_member_not_found, 'Invalid member')] }
2020
end
2121

2222
::Namespaces::Members::DeleteService.new(

app/graphql/mutations/namespaces/members/invite.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ def resolve(namespace_id:, user_id:)
1616
namespace = SagittariusSchema.object_from_id(namespace_id)
1717
user = SagittariusSchema.object_from_id(user_id)
1818

19-
return { namespace_member: nil, errors: [create_message_error('Invalid namespace')] } if namespace.nil?
20-
return { namespace_member: nil, errors: [create_message_error('Invalid user')] } if user.nil?
19+
if namespace.nil?
20+
return { namespace_member: nil,
21+
errors: [create_error(:namespace_not_found, 'Invalid namespace')] }
22+
end
23+
return { namespace_member: nil, errors: [create_error(:user_not_found, 'Invalid user')] } if user.nil?
2124

2225
::Namespaces::Members::InviteService.new(
2326
current_authentication,

app/graphql/mutations/namespaces/projects/assign_runtimes.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ def resolve(namespace_project_id:, runtime_ids:)
1717
namespace_project = SagittariusSchema.object_from_id(namespace_project_id)
1818
runtimes = runtime_ids.map { |runtime_id| SagittariusSchema.object_from_id(runtime_id) }
1919

20-
return { namespace_project: nil, errors: [create_message_error('Invalid project')] } if namespace_project.nil?
21-
return { namespace_project: nil, errors: [create_message_error('Invalid runtime')] } if runtimes.any?(&:nil?)
20+
if namespace_project.nil?
21+
return { namespace_project: nil,
22+
errors: [create_error(:project_not_found, 'Invalid project')] }
23+
end
24+
if runtimes.any?(&:nil?)
25+
return { namespace_project: nil,
26+
errors: [create_error(:runtime_not_found, 'Invalid runtime')] }
27+
end
2228

2329
::Namespaces::Projects::AssignRuntimesService.new(
2430
current_authentication,

app/graphql/mutations/namespaces/projects/create.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def resolve(namespace_id:, **params)
1919

2020
if namespace.nil?
2121
return { organization_project: nil,
22-
errors: [create_message_error('Invalid namespace')] }
22+
errors: [create_error(:namespace_not_found, 'Invalid namespace')] }
2323
end
2424

2525
::Namespaces::Projects::CreateService.new(

app/graphql/mutations/namespaces/projects/delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def resolve(namespace_project_id:)
1616

1717
if project.nil?
1818
return { organization_project: nil,
19-
errors: [create_message_error('Invalid project')] }
19+
errors: [create_error(:project_not_found, 'Invalid project')] }
2020
end
2121

2222
::Namespaces::Projects::DeleteService.new(

app/graphql/mutations/namespaces/projects/flows/create.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ class Create < BaseMutation
1717
def resolve(project_id:, flow:, **_params)
1818
project = SagittariusSchema.object_from_id(project_id)
1919

20-
return error('Invalid project id') if project.nil?
20+
if project.nil?
21+
return {
22+
flow: nil,
23+
errors: [create_error(:project_not_found, 'Invalid project id')],
24+
}
25+
end
2126

2227
flow_type = SagittariusSchema.object_from_id(flow.type)
23-
return error('Invalid flow type id') if flow_type.nil?
28+
if flow_type.nil?
29+
return {
30+
flow: nil,
31+
errors: [create_error(:flow_type_not_found, 'Invalid flow type id')],
32+
}
33+
end
2434

2535
::Namespaces::Projects::Flows::CreateService.new(
2636
current_authentication,
@@ -31,13 +41,6 @@ def resolve(project_id:, flow:, **_params)
3141
name: flow.name
3242
).execute.to_mutation_response(success_key: :flow)
3343
end
34-
35-
def error(message)
36-
{
37-
flow: nil,
38-
errors: [create_message_error(message)],
39-
}
40-
end
4144
end
4245
end
4346
end

app/graphql/mutations/namespaces/projects/flows/delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def resolve(flow_id:)
1717

1818
if flow.nil?
1919
return { flow: nil,
20-
errors: [create_message_error('Invalid flow')] }
20+
errors: [create_error(:flow_not_found, 'Invalid flow')] }
2121
end
2222

2323
::Namespaces::Projects::Flows::DeleteService.new(

app/graphql/mutations/namespaces/projects/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def resolve(namespace_project_id:, **params)
2121

2222
if project.nil?
2323
return { organization_project: nil,
24-
errors: [create_message_error('Invalid project')] }
24+
errors: [create_error(:project_not_found, 'Invalid project')] }
2525
end
2626

2727
params[:primary_runtime_id] = params[:primary_runtime_id]&.model_id if params.key?(:primary_runtime_id)

0 commit comments

Comments
 (0)