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