Skip to content

Commit

Permalink
JPush: Set deffered status at correct error response code
Browse files Browse the repository at this point in the history
Issue: HKGO-1801

Reviewed at https://reviews.lunr.nl/r/995/
  • Loading branch information
brianstoop committed Jul 7, 2023
1 parent 75a0a66 commit f9fc9d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Lunr/Vortex/JPush/JPushReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,22 @@ public function get_status(string $endpoint): int
*/
private function report_error(Requests_Response $response, array &$endpoints): void
{
$upstream_msg = NULL;
$upstream_msg = NULL;
$upstream_code = NULL;

if (!empty($response->body))
{
$body = json_decode($response->body, TRUE);
$upstream_msg = $body['error']['message'] ?? NULL;
$body = json_decode($response->body, TRUE);
$upstream_msg = $body['error']['message'] ?? NULL;
$upstream_code = $body['error']['code'] ?? NULL;
}

$status = PushNotificationStatus::ERROR;

switch ($response->status_code)
{
case 400:
if ($upstream_msg === 'Msgid does not exist')
if ($upstream_code === 3002)
{
$status = PushNotificationStatus::DEFERRED;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lunr/Vortex/JPush/Tests/JPushReportReportErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public function testReportEndpointErrorSucceedsWhenResponseIsDeferred(): void

$this->logger->expects($this->once())
->method('warning')
->with('Getting JPush notification report failed: {error}', [ 'error' => 'Msgid does not exist' ]);
->with('Getting JPush notification report failed: {error}', [ 'error' => 'Msgid does not exist.' ]);

$this->response->status_code = 400;
$this->response->body = '{"error":{"message":"Msgid does not exist"}}';
$this->response->body = '{"error":{"message":"Msgid does not exist.","code":3002}}';

$method = $this->get_accessible_reflection_method('report_error');
$method->invokeArgs($this->class, [ $this->response, &$endpoints ]);
Expand Down

0 comments on commit f9fc9d7

Please sign in to comment.