Post/Delete GPG keys: Do not return 409 Conflict if an error occurred
If an error occurs the response should be 500 Internal Server Error.
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I5f432d1f1a6f12bf43e2de19c91588829d15dc2f
(cherry picked from commit 347eb3cf41
)
This commit is contained in:

committed by
David Pursehouse

parent
04dd9b2d8a
commit
9790275c12
@@ -21,8 +21,8 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gerrit.exceptions.EmailException;
|
||||
import com.google.gerrit.exceptions.StorageException;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -108,9 +108,10 @@ public class DeleteGpgKey implements RestModifyView<GpgKey, Input> {
|
||||
rsrc.getUser().getAccount().getPreferredEmail());
|
||||
}
|
||||
break;
|
||||
case LOCK_FAILURE:
|
||||
// should not happen since this case is already handled by PublicKeyStore#save
|
||||
case FORCED:
|
||||
case IO_FAILURE:
|
||||
case LOCK_FAILURE:
|
||||
case NEW:
|
||||
case NOT_ATTEMPTED:
|
||||
case REJECTED:
|
||||
@@ -119,7 +120,7 @@ public class DeleteGpgKey implements RestModifyView<GpgKey, Input> {
|
||||
case REJECTED_MISSING_OBJECT:
|
||||
case REJECTED_OTHER_REASON:
|
||||
default:
|
||||
throw new ResourceConflictException("Failed to delete public key: " + saveResult);
|
||||
throw new StorageException(String.format("Failed to delete public key: %s", saveResult));
|
||||
}
|
||||
}
|
||||
return Response.none();
|
||||
|
@@ -28,6 +28,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gerrit.exceptions.EmailException;
|
||||
import com.google.gerrit.exceptions.StorageException;
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeysInput;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
@@ -248,8 +249,9 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
|
||||
break;
|
||||
case NO_CHANGE:
|
||||
break;
|
||||
case IO_FAILURE:
|
||||
case LOCK_FAILURE:
|
||||
// should not happen since this case is already handled by PublicKeyStore#save
|
||||
case IO_FAILURE:
|
||||
case NOT_ATTEMPTED:
|
||||
case REJECTED:
|
||||
case REJECTED_CURRENT_BRANCH:
|
||||
@@ -257,8 +259,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
|
||||
case REJECTED_MISSING_OBJECT:
|
||||
case REJECTED_OTHER_REASON:
|
||||
default:
|
||||
// TODO(dborowitz): Backoff and retry on LOCK_FAILURE.
|
||||
throw new ResourceConflictException("Failed to save public keys: " + saveResult);
|
||||
throw new StorageException(String.format("Failed to save public keys: %s", saveResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user