[API] Subscribing user to issue produces nil in API reponse #8284

Closed
opened 2025-11-02 08:00:56 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @realaravinth on GitHub (Dec 24, 2021).

Gitea Version

743-g7cc44491f

Git Version

No response

Operating System

No response

How are you running Gitea?

Tested on https://try.gitea.io

Database

No response

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

When subscribing a user through the API to an issue, it returns the following error when the operation is forbidden:

{
  "message": "%!s(<nil>)",
  "url": "https://try.gitea.io/api/swagger"
}

This is probably harmless but can be fixed to return an appropriate error message like so:

{
 "message": "Only admin and user for itself can change subscription",
"url": "https://try.gitea.io/api/swagger"
}

The problem seems to be in this line:
7cc44491fa/routers/api/v1/repo/issue_subscription.go (L131)

I'll be happy to submit a patch to this effect!

Screenshots

image

Originally created by @realaravinth on GitHub (Dec 24, 2021). ### Gitea Version 743-g7cc44491f ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? Tested on https://try.gitea.io ### Database _No response_ ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Description When subscribing a user through the API to an issue, it returns the following error when the operation is forbidden: ```json { "message": "%!s(<nil>)", "url": "https://try.gitea.io/api/swagger" } ``` This is probably harmless but can be fixed to return an appropriate error message like so: ```json { "message": "Only admin and user for itself can change subscription", "url": "https://try.gitea.io/api/swagger" } ``` The problem seems to be in this line: https://github.com/go-gitea/gitea/blob/7cc44491fae1e5f00616a5b8d8da2934a8a619f8/routers/api/v1/repo/issue_subscription.go#L131 I'll be happy to submit a patch to this effect! ### Screenshots ![image](https://user-images.githubusercontent.com/33521410/147348285-461efe74-0fac-4b6e-9090-fea898c7a604.png)
Author
Owner

@zeripath commented on GitHub (Dec 24, 2021):

This can only occur if you're trying to subscribe a user that isn't the logged in user or you're not the admin.

It will be coming from

	//only admin and user for itself can change subscription
	if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
		ctx.Error(http.StatusForbidden, "User", nil)
		return
	}
@zeripath commented on GitHub (Dec 24, 2021): This can only occur if you're trying to subscribe a user that isn't the logged in user or you're not the admin. It will be coming from ```go //only admin and user for itself can change subscription if user.ID != ctx.User.ID && !ctx.User.IsAdmin { ctx.Error(http.StatusForbidden, "User", nil) return } ```
Author
Owner

@realaravinth commented on GitHub (Dec 24, 2021):

The error(403 forbidden) is alright and is working according to spec but I was referring to the message. It's a minor thing but a descriptive error message might come in handy while debugging

@realaravinth commented on GitHub (Dec 24, 2021): The error(403 forbidden) is alright and is working according to spec but I was referring to the message. It's a minor thing but a descriptive error message might come in handy while debugging
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8284