Handle GlobalIDs with invalid resource names
What does this MR do?
A GID with an invalid model_name
portion previously threw an
unhandled NameError
when parsed by Types::GlobalIDType
due to #model_class
calling constantize
on the String
:
GlobalID.new("gid://gitlab/invalid_name/7").model_class
# => NameError: wrong constant name invalid_name
The API client would receive our generic unhandled error response:
{
"errors": [
{
"message": "Internal server error: wrong constant name <resource name>"
}
]
}
This change handles this situation as a GraphQL::CoercionError
and the error response for the client is:
{
"errors": [
{
"message": "\"gid://gitlab/<resource name>/1\" does not represent an instance of <expected resource>"
}
]
}
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Edited by Luke Duncalfe