Commit 1f2387c4 authored by Achilleas Pipinellis's avatar Achilleas Pipinellis

Merge branch '62356-service-response-docs' into 'master'

Add doc for ServiceResponse

Closes #62356

See merge request gitlab-org/gitlab-ce!29992
parents 7f6de7fe b32f7d48
......@@ -127,6 +127,42 @@ Everything in `lib/api`.
Everything that resides in `app/services`.
#### ServiceResponse
Service classes usually have an `execute` method, which can return a
`ServiceResponse`. You can use `ServiceResponse.success` and
`ServiceResponse.error` to return a response in `execute` method.
In a successful case:
``` ruby
response = ServiceResponse.success(message: 'Branch was deleted')
response.success? # => true
response.error? # => false
response.status # => :success
response.message # => 'Branch was deleted'
```
In a failed case:
``` ruby
response = ServiceResponse.error(message: 'Unsupported operation')
response.success? # => false
response.error? # => true
response.status # => :error
response.message # => 'Unsupported operation'
```
An additional payload can also be attached:
``` ruby
response = ServiceResponse.success(payload: { issue: issue })
response.payload[:issue] # => issue
```
### Finders
Everything in `app/finders`, typically used for retrieving data from a database.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment