Skip to content

Commit 3b5b841

Browse files
send 메소드 접수 실패 검사 강화
1 parent 79cfa1a commit 3b5b841

4 files changed

Lines changed: 51 additions & 9 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Exception;
66

7-
class SolapiCurlException extends Exception
7+
class CurlException extends Exception
88
{
99

1010
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Nurigo\Solapi\Exceptions;
4+
5+
use Exception;
6+
7+
class MessageNotReceivedException extends Exception
8+
{
9+
/**
10+
* @var array
11+
*/
12+
public $failedMessageList;
13+
14+
/**
15+
* @param array $failedMessageList
16+
*/
17+
public function __construct(array $failedMessageList)
18+
{
19+
$this->failedMessageList = $failedMessageList;
20+
parent::__construct("메시지 접수에 실패했습니다.");
21+
}
22+
23+
/**
24+
* @return array
25+
*/
26+
public function getFailedMessageList(): array
27+
{
28+
return $this->failedMessageList;
29+
}
30+
}

src/Libraries/Fetcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Nurigo\Solapi\Libraries;
44

55
use Exception;
6-
use Nurigo\Solapi\Exceptions\SolapiCurlException;
6+
use Nurigo\Solapi\Exceptions\CurlException;
77

88
class Fetcher
99
{
@@ -37,7 +37,7 @@ public function __destruct()
3737
* @param string $uri
3838
* @param mixed $data
3939
* @return mixed
40-
* @throws Exception|SolapiCurlException CURL 관련된 Exception
40+
* @throws Exception|CurlException CURL 관련된 Exception
4141
*/
4242
public function request(string $method, string $uri, $data = false)
4343
{
@@ -64,7 +64,7 @@ public function request(string $method, string $uri, $data = false)
6464
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
6565
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
6666
if (curl_error($curl)) {
67-
throw new SolapiCurlException(curl_error($curl));
67+
throw new CurlException(curl_error($curl));
6868
}
6969
$result = curl_exec($curl);
7070
curl_close($curl);

src/Services/SolapiMessageService.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use DateTime;
66
use Exception;
7-
use Nurigo\Solapi\Exceptions\SolapiCurlException;
7+
use Nurigo\Solapi\Exceptions\CurlException;
8+
use Nurigo\Solapi\Exceptions\MessageNotReceivedException;
89
use Nurigo\Solapi\Libraries\Fetcher;
910
use Nurigo\Solapi\Models\Message;
1011
use Nurigo\Solapi\Models\Request\SendRequest;
12+
use stdClass;
1113

1214
class SolapiMessageService
1315
{
@@ -25,15 +27,25 @@ public function __construct(string $apiKey, string $apiSecretKey)
2527
* 메시지 발송
2628
* @param Message|Message[] $messages
2729
* @param DateTime|null $scheduledDateTime
28-
* @throws Exception|SolapiCurlException
29-
* @return mixed
30+
* @return stdClass
31+
* @throws Exception|CurlException|MessageNotReceivedException
3032
*/
31-
public function send($messages, DateTime $scheduledDateTime = null)
33+
public function send($messages, DateTime $scheduledDateTime = null): stdClass
3234
{
3335
if (!is_array($messages)) {
3436
$messages = array($messages);
3537
}
3638
$requestParameter = new SendRequest($messages, $scheduledDateTime);
37-
return $this->fetcherInstance->request("POST", "/messages/v4/send-many/detail", $requestParameter);
39+
$response = $this->fetcherInstance->request("POST", "/messages/v4/send-many/detail", $requestParameter);
40+
41+
$count = $response->groupInfo->count;
42+
if (
43+
(is_array($response->failedMessageList) && count($response->failedMessageList)) &&
44+
((int)$count->total === (int)$count->registeredFailed)
45+
) {
46+
throw new MessageNotReceivedException($response->failedMessageList);
47+
}
48+
49+
return $response;
3850
}
3951
}

0 commit comments

Comments
 (0)