Skip to content

Bubble up API error message for bulk import

Jessie Young requested to merge jy-specific-error into master

What does this MR do and why?

  • Previously, we were rescuing any error from BulkImports::NetworkError and returning the "setting not enabled" error message.
  • The was sometimes an accurate error message, but sometimes it was inaccurate because the API request can also fail because of a 403 (authorization error if the requesting user is not an admin on the project or group)
  • Now, we are still returning the 404 / "setting not enabled" error when that is what the API returns, but we are instead returning a 403 when the response is a 403.
  • The 404 being returned when it is really a 403 is confusing and misleading so this fix improves the API UX.
  • !131340 (comment 1552306064)

How to set up and validate locally

  1. Enable instance setting for bulk import / direct transfer on both gitlab instances (this is already enabled for GitLab.com)
  2. Make a curl request for a bulk import using a valid access token (GITLAB_PAT) that belongs to a member of a project who is not an admin
curl --request POST --header "PRIVATE-TOKEN: GDK_PAT" "https://gdk.test:3443/api/v4/bulk_imports" \
  --header "Content-Type: application/json" \
  --data '{
    "configuration": {
      "url": "https://gitlab.com",
      "access_token": "GITLAB_PAT"
    },
    "entities": [
      {
        "source_full_path": "gitlab-migration-large-import-test/migration-test-project",
        "source_type": "project_entity",
        "destination_slug": "migration-test-project",
        "destination_namespace": "root"
      }
    ]
  }'

2.** Before this MR:** error message is "Group import disabled on source or destination instance. Ask an administrator to enable it on both instances and try again.". With changes in this MR: error message is "403 Forbidden" 3. Try the above request again with a GITALB_PAT for an owner of the group or project that is being imported. The request should succeed. 4. Disable the "Allow migrating GitLab groups and projects by direct transfer" setting on one of the instances. The request should error with the message "Group import disabled on source or destination instance. Ask an administrator to enable it on both instances and try again."

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 Jessie Young

Merge request reports