theonedev/onedev · error · ClientException

406

Error message

406

What it means

checkProject() throws a ClientException with HTTP status 406 (Not Acceptable) when the target project does not have package management (pack management) enabled. The NuGet pack endpoint refuses to serve packages for projects where the feature is turned off.

Source

Thrown at server-plugin/server-plugin-pack-nuget/src/main/java/io/onedev/server/plugin/pack/nuget/NugetPackHandler.java:619

	private String getPackageDownloadUrl(String baseUrl, String name, String version) {
		name = encodePath(name);
		version = encodePath(version);
		return baseUrl + "/package/" + name + "/" + version + "/" + name + "." + version + ".nupkg";
	}
	
	private void sendResponse(HttpServletResponse response, Object value) {
		try {
			response.getOutputStream().write(writeJson(value));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	private Project checkProject(Long projectId, boolean needsToWrite) {
		var project = projectService.load(projectId);
		if (!project.isPackManagement()) {
			logger.warn("Package management not enabled for project '" + project.getPath() + "'");
			throw new ClientException(SC_NOT_ACCEPTABLE);
		} else if (needsToWrite && !SecurityUtils.canWritePack(project)) {
			throw new UnauthorizedException("No package write permission for project: " + project.getPath());
		} else if (!needsToWrite && !SecurityUtils.canReadPack(project)) {
			throw new UnauthorizedException("No package read permission for project: " + project.getPath());
		}
		return project;
	}

	@Override
	public String getApiKey(HttpServletRequest request) {
		return request.getHeader(HEADER_API_KEY);
	}
	
	@Override
	public List<String> normalize(List<String> pathSegments) {
		return pathSegments;
	}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Enable package management for the project in the OneDev project settings, then retry.
  2. Verify you are using the correct project ID / URL for the project that has pack management enabled.
  3. If the package belongs to a different project, update your nuget.config / CI publish URL to point at that project's pack endpoint.

Example fix

// before: project without pack management
POST /~nuget/pack/<projectIdWithoutFeature>/...
// after: enable Pack Management on the project in OneDev UI, or use the right projectId
Defensive patterns

Strategy: validation

Validate before calling

# before publishing, confirm pack management is enabled via OneDev REST:
# GET /api/projects/{id} and check pack management enabled flag

Try / catch

resp = requests.post(url, ...)
if resp.status_code == 406:
    raise RuntimeError('Enable pack management on project first')

Prevention

When it happens

Trigger: Calling any NuGet pack endpoint (publish, search, download) against a projectId whose project has 'Pack management' disabled in its settings.

Common situations: Pointing a nuget source/publish URL at the wrong project, creating a new project and forgetting to enable pack management before running a CI publish step, or a project template that does not include the feature.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/e78e6bd1a37a97e0. Report an issue: GitHub.