Merge "Remove overbroad DB error catching in ApiEchoPushSubscriptionsCreate"

This commit is contained in:
jenkins-bot 2020-06-10 11:52:35 +00:00 committed by Gerrit Code Review
commit ea200ace05
2 changed files with 7 additions and 7 deletions

View file

@ -47,9 +47,9 @@ class SubscriptionManager extends EchoAbstractMapper {
* @param User $user
* @param string $provider Provider name string (validated by presence in the PARAM_TYPE array)
* @param string $token Subscriber token provided by the push provider
* @throws DBError if the subscription ID already exists in the DB
* @return bool true if the subscription was created; false if the token already exists
*/
public function create( User $user, string $provider, string $token ): void {
public function create( User $user, string $provider, string $token ): bool {
$this->dbw->insert(
'echo_push_subscription',
[
@ -59,8 +59,10 @@ class SubscriptionManager extends EchoAbstractMapper {
'eps_token_sha256' => hash( 'sha256', $token ),
'eps_updated' => $this->dbw->timestamp()
],
__METHOD__
__METHOD__,
[ 'IGNORE' ]
);
return (bool)$this->dbw->affectedRows();
}
/**

View file

@ -4,7 +4,6 @@ namespace EchoPush\Api;
use ApiBase;
use ApiMain;
use DBError;
use EchoPush\SubscriptionManager;
use EchoServices;
use Wikimedia\ParamValidator\ParamValidator;
@ -59,9 +58,8 @@ class ApiEchoPushSubscriptionsCreate extends ApiBase {
public function execute(): void {
$provider = $this->getParameter( 'provider' );
$token = $this->getParameter( 'providertoken' );
try {
$this->subscriptionManager->create( $this->getUser(), $provider, $token );
} catch ( DBError $e ) {
$success = $this->subscriptionManager->create( $this->getUser(), $provider, $token );
if ( !$success ) {
$this->dieWithError( 'apierror-echo-push-token-exists' );
}
}