Skip to content

Commit 8a9ce6d

Browse files
committed
Update SignedRequest example to handle ValidationExceptions
If expected values are missing or invalid when calling createFromGlobals() an exception is thrown. The example now demonstrates how an implementation can handle this and respond cleanly.
1 parent f033570 commit 8a9ce6d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/signedrequest-verification.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
$requestValidator = new \MessageBird\RequestValidator('YOUR_SIGNING_KEY');
77

88
// Set up the signed request from the PHP global variables.
9-
$request = \MessageBird\Objects\SignedRequest::createFromGlobals();
9+
try {
10+
$request = \MessageBird\Objects\SignedRequest::createFromGlobals();
11+
} catch (\MessageBird\Exceptions\ValidationException $e) {
12+
// The request was missing expected values, so respond accordingly.
13+
http_response_code(412);
14+
}
1015

1116
if (!$requestValidator->verify($request)) {
1217
// The request was invalid, so respond accordingly.

0 commit comments

Comments
 (0)