diff --git a/docs/api/README.md b/docs/api/README.md index 5bef46a3a..5559a4ce3 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -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 @@ -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. diff --git a/lib/flipper/api/error_response.rb b/lib/flipper/api/error_response.rb index a3aa9e380..cd11bdf53 100644 --- a/lib/flipper/api/error_response.rb +++ b/lib/flipper/api/error_response.rb @@ -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 @@ -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 diff --git a/spec/flipper/api/action_spec.rb b/spec/flipper/api/action_spec.rb index 0ca5b937a..088d64cbc 100644 --- a/spec/flipper/api/action_spec.rb +++ b/spec/flipper/api/action_spec.rb @@ -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 @@ -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 diff --git a/spec/flipper/api/v1/actions/actors_gate_spec.rb b/spec/flipper/api/v1/actions/actors_gate_spec.rb index 62a677de5..84bdee825 100644 --- a/spec/flipper/api/v1/actions/actors_gate_spec.rb +++ b/spec/flipper/api/v1/actions/actors_gate_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/flipper/api/v1/actions/feature_spec.rb b/spec/flipper/api/v1/actions/feature_spec.rb index 616076f06..b404419fc 100644 --- a/spec/flipper/api/v1/actions/feature_spec.rb +++ b/spec/flipper/api/v1/actions/feature_spec.rb @@ -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 @@ -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 diff --git a/spec/flipper/api/v1/actions/features_spec.rb b/spec/flipper/api/v1/actions/features_spec.rb index 921ff4c61..c97be4ad0 100644 --- a/spec/flipper/api/v1/actions/features_spec.rb +++ b/spec/flipper/api/v1/actions/features_spec.rb @@ -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 diff --git a/spec/flipper/api/v1/actions/groups_gate_spec.rb b/spec/flipper/api/v1/actions/groups_gate_spec.rb index 943451626..ef61f4ce6 100644 --- a/spec/flipper/api/v1/actions/groups_gate_spec.rb +++ b/spec/flipper/api/v1/actions/groups_gate_spec.rb @@ -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 @@ -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 diff --git a/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb b/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb index 630c1b5c2..4826fb380 100644 --- a/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb +++ b/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb b/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb index c1f7f07b1..25681c244 100644 --- a/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb +++ b/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb @@ -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 @@ -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 @@ -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 @@ -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