Skip to content

Commit

Permalink
Add error documentation url to Api ErrorResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWheeler committed Nov 19, 2016
1 parent 001caa4 commit c407aa5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
6 changes: 3 additions & 3 deletions docs/api/README.md
Expand Up @@ -775,17 +775,16 @@ Successful disabling of a percentage of time will set the percentage to 0 and re
```

## Errors
In the event of an error the Flipper API will return an error object. The error object will contain a Flipper-specific error code, an error message, and a link to the documentation for the given error code.
In the event of an error the Flipper API will return an error object. The error object will contain a Flipper-specific error code, an error message, and a link to documentation providing more information about the error.

*example error object*
```json
{
"code": 1,
"message": "Feature not found",
"more_info": "https://github.com/jnunemaker/flipper/...",
"more_info": "https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference",
}
```

### Error Code Reference

#### 1: Feature Not Found
Expand All @@ -805,4 +804,5 @@ The `percentage` parameter is invalid or missing. `percentage` must be an integ
The `flipper_id` parameter is invalid or missing. `flipper_id` cannot be empty.

#### 5: Name Invalid

The `name` parameter is missing. Make sure your request's body contains a `name` parameter.
15 changes: 8 additions & 7 deletions lib/flipper/api/error_response.rb
Expand Up @@ -4,10 +4,10 @@ module ErrorResponse
class Error
attr_reader :http_status

def initialize(code, message, info, http_status)
def initialize(code, message, http_status)
@code = code
@message = message
@more_info = info
@more_info = "https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference"
@http_status = http_status
end

Expand All @@ -21,12 +21,13 @@ def as_json
end

ERRORS = {
feature_not_found: Error.new(1, "Feature not found.", "", 404),
group_not_registered: Error.new(2, "Group not registered.", "", 404),
percentage_invalid: Error.new(3, "Percentage must be a positive number less than or equal to 100.", "", 422),
flipper_id_invalid: Error.new(4, "Required parameter flipper_id is missing.", "", 422),
name_invalid: Error.new(5, "Required parameter name is missing.", "", 422),
feature_not_found: Error.new(1, "Feature not found.", 404),
group_not_registered: Error.new(2, "Group not registered.", 404),
percentage_invalid: Error.new(3, "Percentage must be a positive number less than or equal to 100.", 422),
flipper_id_invalid: Error.new(4, "Required parameter flipper_id is missing.", 422),
name_invalid: Error.new(5, "Required parameter name is missing.", 422),
}

end
end
end
4 changes: 2 additions & 2 deletions spec/flipper/api/action_spec.rb
Expand Up @@ -74,7 +74,7 @@ def delete
expect(headers["Content-Type"]).to eq("application/json")
expect(parsed_body["code"]).to eq(1)
expect(parsed_body["message"]).to eq("Feature not found.")
expect(parsed_body["more_info"]).to eq("")
expect(parsed_body["more_info"]).to eq("https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference")
end
end

Expand All @@ -91,7 +91,7 @@ def delete
expect(headers["Content-Type"]).to eq("application/json")
expect(parsed_body["code"]).to eq(2)
expect(parsed_body["message"]).to eq("Group not registered.")
expect(parsed_body["more_info"]).to eq("")
expect(parsed_body["more_info"]).to eq("https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference")
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/flipper/api/v1/actions/actors_gate_spec.rb
Expand Up @@ -51,7 +51,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -63,7 +63,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -75,7 +75,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -87,7 +87,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 4, 'message' => 'Required parameter flipper_id is missing.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -98,7 +98,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -109,7 +109,7 @@

it 'returns correct error response' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end
end
4 changes: 2 additions & 2 deletions spec/flipper/api/v1/actions/feature_spec.rb
Expand Up @@ -105,7 +105,7 @@
end

it 'returns formatted error response body' do
expect(json_response).to eq({ "code" => 1, "message" => "Feature not found.", "more_info" => "" })
expect(json_response).to eq({ "code" => 1, "message" => "Feature not found.", "more_info" => "https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference" })
end
end
end
Expand All @@ -131,7 +131,7 @@
end

it 'returns formatted error response body' do
expect(json_response).to eq({ "code" => 1, "message" => "Feature not found.", "more_info" => "" })
expect(json_response).to eq({ "code" => 1, "message" => "Feature not found.", "more_info" => "https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference" })
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/flipper/api/v1/actions/features_spec.rb
Expand Up @@ -134,7 +134,7 @@
end

it 'returns formatted error' do
expect(json_response).to eq({ 'code' => 5, 'message' => 'Required parameter name is missing.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 5, 'message' => 'Required parameter name is missing.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/flipper/api/v1/actions/groups_gate_spec.rb
Expand Up @@ -57,7 +57,7 @@

it '404s with correct error response when feature does not exist' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -69,7 +69,7 @@

it '404s with correct error response when group not registered' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 2, 'message' => 'Group not registered.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 2, 'message' => 'Group not registered.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end
end
8 changes: 4 additions & 4 deletions spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb
Expand Up @@ -43,7 +43,7 @@

it '404s with correct error response when feature does not exist' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -55,7 +55,7 @@

it '422s with correct error response when percentage parameter is invalid' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -67,7 +67,7 @@

it '422s with correct error response when percentage parameter is invalid' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -79,7 +79,7 @@

it '422s with correct error response when percentage parameter is missing' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end
end
8 changes: 4 additions & 4 deletions spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb
Expand Up @@ -42,7 +42,7 @@

it '404s with correct error response when feature does not exist' do
expect(last_response.status).to eq(404)
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 1, 'message' => 'Feature not found.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -54,7 +54,7 @@

it '422s with correct error response when percentage parameter is invalid' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -66,7 +66,7 @@

it '422s with correct error response when percentage parameter is invalid' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end

Expand All @@ -78,7 +78,7 @@

it '422s with correct error response when percentage parameter is missing' do
expect(last_response.status).to eq(422)
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => '' })
expect(json_response).to eq({ 'code' => 3, 'message' => 'Percentage must be a positive number less than or equal to 100.', 'more_info' => 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference' })
end
end
end

0 comments on commit c407aa5

Please sign in to comment.