[Backend] Fix internal server error while deleting non existent destination
Summary
If we pass id of non existent destination as param for destroy instance level external audit event destination api, the API throws Internal server error.
Steps to reproduce
- Visit graphql-explorer by logged in as instance admin.
- Run following graphql query, you can replace id with any non-existing id, you will receive the error.
mutation {
instanceExternalAuditEventDestinationDestroy(input: { id: "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/some_id"}) {
errors
}
}
What is the current bug behavior?
Destroying non existent destination throws internal server error.
What is the expected correct behavior?
API should return an error stating that destination does not exist.
Relevant logs and/or screenshots
Error log:
NoMethodError (undefined method `destroy' for nil:NilClass
destination.destroy
^^^^^^^^):
ee/app/graphql/mutations/audit_events/instance_external_audit_event_destinations/destroy.rb:18:in `resolve'
Possible fixes
Add a check for blank? destination at https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/instance_external_audit_event_destinations/destroy.rb#L16 and raise error.
Edited by Hitesh Raghuvanshi