Fix coupling in internal workflows endpoints
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem
Internal workflows endpoints have the following helper
ee/lib/api/ai/duo_workflows/workflows_internal.rb
def render_response(response)
if response.success?
status :ok
response.payload
else
render_api_error!(response.message, response.reason)
end
end
As seen in code, the response.reason from service is directly used as http status code.
See: https://docs.gitlab.com/development/reusing_abstractions/#serviceresponse
Also, the tests at ee/spec/requests/api/ai/duo_workflows/workflows_internal_spec.rb
should be updated to test scenarios with different service reasons and http status codes.
This issue is created as a follow-up to !202774 (merged)
Implementation
- In RevokeTokenService, do not return http status codes, instead return a reason to the endpoint
- In Internal Workflows Endpoint render_response helper return a http status based on reason, something like
if response.success?
head :ok
elsif response.reason == :some_other_reason
head :bad_request
Edited by 🤖 GitLab Bot 🤖