Skip to content

Fix NoMethodError when an array parameter has an invalid format

Vasilii Iakliushin requested to merge 454477_fix_grape_object_type into master

What does this MR do and why?

Contributes to #454477 (closed)

Problem

We use type: Array that doesn't verify the elements format. If user provides an incorrect format then the server returns a 500 error.

Solution

Use Array[JSON] type that verifies that elements of the array are valid objects. See documentation.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Use Protected branches API to create an incorrect record:
curl --request POST --header "PRIVATE-TOKEN: <PRIVATE_TOKEN>" --header "Content-Type: application/json" --data '{"allowed_to_push": [""], "name": "branch-1"}' "http://gdk.test:3000/api/v4/projects/2/protected_branches"
  1. You should receive an error response: {"error":"allowed_to_push is invalid"}
  2. Before the fix you would receive an Internal error: {"message":"500 Internal Server Error"}
Edited by Vasilii Iakliushin

Merge request reports