IDEA-216363 Report "field invisible to anonymous user" errors as invalid credentials in JIRA

GitOrigin-RevId: 64e89cc4599d33e46f6732a5d03f2b6eac770327
This commit is contained in:
Mikhail Golubev
2019-08-01 17:44:14 +03:00
committed by intellij-monorepo-bot
parent e338e40dd6
commit b2875bdf04
2 changed files with 9 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ jira.failure.no.state.update=Task state cannot be updated in JIRA versions prior
jira.failure.no.time.spent=Time spent cannot be updated in JIRA versions prior 5.0.
jira.failure.captcha=Login failed. Enter captcha in web-interface.
jira.failure.email.address=Login failed. Check your email address.
## YouTrack
youtrack.default.query=for: me sort by: updated #Unresolved

View File

@@ -311,8 +311,15 @@ public class JiraRepository extends BaseRepositoryImpl {
JsonObject object = GSON.fromJson(entityContent, JsonObject.class);
if (object.has("errorMessages")) {
String reason = StringUtil.join(object.getAsJsonArray("errorMessages"), " ");
// something meaningful to user, e.g. invalid field name in JQL query
// If anonymous access is enabled on server, it might reply only with a cryptic 400 error about inaccessible issue fields,
// e.g. "Field 'assignee' does not exist or this field cannot be viewed by anonymous users."
// Unfortunately, there is no better way to indicate such errors other than by matching by the error message itself.
LOG.warn(reason);
if (statusCode == HttpStatus.SC_BAD_REQUEST && reason.contains("cannot be viewed by anonymous users")) {
// Oddly enough, in case of JIRA Cloud issues are access anonymously only if API Token is correct, but email is wrong.
throw new Exception(isInCloud() ? TaskBundle.message("jira.failure.email.address") : TaskBundle.message("failure.login"));
}
// something meaningful to user, e.g. invalid field name in JQL query
throw new Exception(TaskBundle.message("failure.server.message", reason));
}
}