Skip to content

Commit 1562db1

Browse files
committed
Add handler for invalid request to message handler
1 parent 40135cb commit 1562db1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/WorkerJS/PHPClient/TaskMessageRequestHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace WorkerJS\PHPClient;
1010

11+
use WorkerJS\PHPClient\exceptions\InvalidRequestException;
12+
1113
class TaskMessageRequestHandler {
1214
private $client;
1315

@@ -24,6 +26,10 @@ public function handleRequest(string $body) {
2426
$body = json_decode($body);
2527
//TODO: Check protocol
2628

29+
if ($body === null && json_last_error() !== JSON_ERROR_NONE) {
30+
throw new InvalidRequestException("Invalid request");
31+
}
32+
2733
$taskID = $body->taskID;
2834

2935
$task = $this->client->getTaskByID($taskID);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: miljanrakita
5+
* Date: 12/25/18
6+
* Time: 1:34 AM
7+
*/
8+
9+
namespace WorkerJS\PHPClient\exceptions;
10+
11+
12+
class InvalidRequestException extends \Exception {}
13+

0 commit comments

Comments
 (0)