Skip to content

Add `reason` attribute to ServiceResponse

Fabio Pitino requested to merge add-reason-to-service-response into master

What does this MR do and why?

Related to #356036 (closed)

Instead of using http_status which is an infrastructure layer responsibility we can use reason which is more generic and can be better used for internal domain service objects.

Endpoints can then convert the reason value into HTTP status. This pattern also improves the use ob black box unit tests for service objects.

Example

# example of how it could be used:
response = Ci::RetryJobService.new(project, user).execute(job)

if response.success?
  # happy path
elsif response.reason == :permission_denied
  # do something
elsif response.reason == :job_not_retriable
  # do something
else
  # do something else
end

In HTTP endpoints it we could use different status code based on the reason. In internal usages of the service we could use the reason to take different actions.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Fabio Pitino

Merge request reports