Skip to content

Commit 2f54346

Browse files
committed
- throwing specific exception when e-mail address is not valid
1 parent f2c34a6 commit 2f54346

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/MailQ/Connector.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use MailQ\Exceptions\MailQException;
66
use MailQ\Exceptions\UnresolvedMxDomainException;
7+
use MailQ\Exceptions\InvalidEmailAddressException;
78

89
class Connector {
910

@@ -90,7 +91,7 @@ private function createResponse($ch,$response) {
9091
function processError(Response $responseData,$response) {
9192
switch ($responseData->getHttpCode()) {
9293
case 401: throw new MailQException("Invalid API key.",$responseData->getHttpCode());
93-
case 405: throw new MailQException(" Method not allowed.",$responseData->getHttpCode());
94+
case 405: throw new MailQException("Method not allowed.",$responseData->getHttpCode());
9495
default: $this->handleDefaultException($responseData,$response);
9596
}
9697
}
@@ -103,14 +104,18 @@ private function handleDefaultException(Response $responseData,$response) {
103104
}
104105
}
105106
else {
106-
throw new MailQException("Unknonw exception",$responseData->getHttpCode());
107+
throw new MailQException("Unknown exception",$responseData->getHttpCode());
107108
}
108109
}
109110

110111
private function createSpecificException($errorData) {
111-
if ($errorData->message == 'Could not resolve MX domain.') {
112+
// TODO change to resolving messages by errorCode
113+
if ($errorData->message === 'Could not resolve MX domain.') {
112114
throw new UnresolvedMxDomainException($errorData->message,$errorData->code);
113115
}
116+
else if ($errorData->message === 'Invalid recipient email.') {
117+
throw new InvalidEmailAddressException($errorData->message,$errorData->code);
118+
}
114119
else {
115120
throw new MailQException($errorData->message,$errorData->code);
116121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace MailQ\Exceptions;
4+
5+
class InvalidEmailAddressException extends MailQException {
6+
7+
8+
}

0 commit comments

Comments
 (0)