Skip to content

Commit

Permalink
combine 2 email exceptions into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddhuy committed Nov 30, 2017
1 parent ff97d9f commit b001a77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import org.restcomm.connect.http.exceptions.AuthorizationException;
import org.restcomm.connect.http.exceptions.EmailAlreadyExisted;
import org.restcomm.connect.http.exceptions.InsufficientPermission;
import org.restcomm.connect.http.exceptions.InvalidEmailFormat;
import org.restcomm.connect.http.exceptions.InvalidEmailException;
import org.restcomm.connect.http.exceptions.PasswordTooWeak;
import org.restcomm.connect.http.exceptions.RcmlserverNotifyError;
import org.restcomm.connect.identity.EmailValidator;
Expand Down Expand Up @@ -465,7 +465,7 @@ private Client createClientFrom(final Sid accountSid, final MultivaluedMap<Strin
* @throws AccountAlreadyClosed
*/
private Account prepareAccountForUpdate(final Account account, final MultivaluedMap<String, String> data)
throws AccountAlreadyClosed, PasswordTooWeak, EmailAlreadyExisted, InvalidEmailFormat {
throws AccountAlreadyClosed, PasswordTooWeak, EmailAlreadyExisted, InvalidEmailException {
Account result = account;
boolean isPasswordReset = false;
Account.Status newStatus = null;
Expand Down Expand Up @@ -513,14 +513,14 @@ private Account prepareAccountForUpdate(final Account account, final Multivalued
if (data.containsKey("EmailAddress")) {
String newEmailAddress = data.getFirst("EmailAddress").toLowerCase();
if (!EmailValidator.isValidEmailFormat(newEmailAddress)) {
throw new InvalidEmailFormat();
throw new InvalidEmailException();
}
if (accountsDao.getAccount(newEmailAddress) != null) {
throw new EmailAlreadyExisted();
}
result = result.setEmailAddress(newEmailAddress);
}
} catch (AuthorizationException | AccountAlreadyClosed | PasswordTooWeak | EmailAlreadyExisted | InvalidEmailFormat e) {
} catch (AuthorizationException | AccountAlreadyClosed | PasswordTooWeak | EmailAlreadyExisted | InvalidEmailException e) {
// some exceptions should reach outer layers and result in 403
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.restcomm.connect.email.api.Mail;
import org.restcomm.connect.http.converter.EmailMessageConverter;
import org.restcomm.connect.http.converter.RestCommResponseConverter;
import org.restcomm.connect.http.exceptions.InvalidEmailException;
import org.restcomm.connect.identity.EmailValidator;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -258,16 +259,6 @@ public void onReceive(final Object message) throws Exception {
}
}

private static class InvalidEmailException extends Exception {
//Parameterless Constructor
public InvalidEmailException() {}

//Constructor that accepts a message
public InvalidEmailException(String message) {
super(message);
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

package org.restcomm.connect.http.exceptions;

import org.restcomm.connect.commons.exceptions.RestcommRuntimeException;


/**
* @author [email protected] (Huy Dang)
*/
public class InvalidEmailFormat extends RestcommRuntimeException {
public class InvalidEmailException extends RuntimeException {
//Parameterless Constructor
public InvalidEmailException() {}

//Constructor that accepts a message
public InvalidEmailException(String message) {
super(message);
}
}

0 comments on commit b001a77

Please sign in to comment.