Skip to content

API should return JSON on errors even if custom error pages are used

What does this MR do?

Currently, with Omnibus installations, when a custom error page of any kind defined, the GitLab API returns an HTML page, instead of a valid JSON response in error cases (e.g. for 404 resource not found).

The reason for the behavior is that, as soon as a custom error page is defined in gitlab.rb, the following line in Omnnibus (containing proxy_intercept_errors on regardless of path) also has the side-effect that the API enndpoints also return HTML pages:

Example request:

curl https://<gitlab-instance>/api/v4/projects/a-non-existing-project

Current response:

<!DOCTYPE html>
<html>
<head>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
  <title>The page you're looking for could not be found (404)</title>
...

Desired response:

The expected behaviour for the API is that it returns a JSON object with the following response when a request is made to non-existing project

{"message":"404 Project Not Found"}

This MR aims to avoid sending HTML pages from the GitLab API, instead sends JSON response, regardless of whether custom error pages are defined or not.

Locally tested and verified with our instance that this might be a viable direction to pursue.

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com
  • Pipeline is green on dev.gitlab.org if the change is touching anything besides documentation or internal cookbooks
  • trigger-package has a green pipeline running against latest commit

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Tests added
  • Integration tests added to GitLab QA
  • Equivalent MR/issue for the GitLab Chart opened

🛠 with at Siemens

/cc @fh1ch @bufferoverflow @dlouzan @max-wittig

Edited by Balasankar 'Balu' C

Merge request reports

Loading