Fix JSON format in some controller actions

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

There are some controller actions rendering strings instead of JSON. We should do render json: {error: 'any string'} instead of render json: 'any string'`

app/controllers/concerns/uploads_actions.rb:    render json: "Error uploading file", status: :internal_server_error
app/controllers/projects/merge_requests_controller.rb:      render json: '', status: :no_content
app/controllers/admin/users_controller.rb:        format.json { render json: 'There was an error removing the e-mail.', status: :bad_request }
app/controllers/application_controller.rb:      format.js { render json: '', status: :not_found, content_type: 'application/json' }
app/controllers/concerns/uploads_actions.rb:          render json: 'Invalid file.', status: :unprocessable_entity

The following discussion from gitlab-ce!21774 should be addressed:

  • @stanhu started a discussion: (+1 comment)

    That's not valid JSON either:

    irb(main):002:0> JSON.parse('Invalid JSON')
    JSON::ParserError: 765: unexpected token at 'Invalid JSON'

    I'd suggest either: { error: 'Invalid UTF-8'} or just {}.

    Can we add a spec please?

Edited Sep 25, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading