Loading
Return 422 when a managed resource is not publicly accessible
What does this MR do and why?
Resolves #715 (closed)
When an issue or merge request action targets a resource that is private or does not exist, check_public! raised a bare StandardError, which surfaced as a 500.
This MR:
- introduces
GitlabRestService::NotPubliclyAccessibleError, raised bycheck_public!on a403or404instead ofStandardError. - raises
GitlabRestService::GitlabResponseFailurefor any other unsuccessful response, so rate limits and server errors still return a500. - rescues it in
Api::V1::ApiApplicationController, which covers the merge requesthelp,request_reviewandlabelactions and the issueassign,unassign,closeandlabelactions. - rescues it in
ManageMergeRequestController#request_help, which does not inherit from the API base controller. - returns a
422with{ "error": "Resource is not publicly accessible" }in both cases, without posting a note or awarding bonus points. - regenerates
doc/openapi.yamlandtypes.gen.ts, as the new request specs add a422response to all seven affected actions.
Validation steps
bundle exec rspec spec/services/gitlab_rest_service_spec.rb spec/requests/manage_merge_request_controller_spec.rb spec/requests/api/v1/api_application_controller_spec.rb spec/requests/api/v1/manage_merge_request_controller_spec.rb spec/requests/api/v1/manage_issue_controller_spec.rbbin/generate_api_typesbundle exec rspec
Edited by Salim Zidane