Skip to content

Commit 1c8284e

Browse files
authored
Merge pull request #125 from matthewhall-ca/main
Adding Response Metadata to Slack Error Responses
2 parents 1b85be6 + c9f3ee9 commit 1c8284e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Exception/SlackErrorResponse.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ class SlackErrorResponse extends \Exception
1717
{
1818
private $errorCode;
1919

20-
public function __construct(string $errorCode, \Throwable $previous = null)
20+
private $responseMetadata;
21+
22+
public function __construct(string $errorCode, ?array $responseMetadata, \Throwable $previous = null)
2123
{
2224
$this->errorCode = $errorCode;
2325

26+
$this->responseMetadata = $responseMetadata;
27+
2428
parent::__construct(sprintf('Slack returned error code "%s"', $errorCode), 0, $previous);
2529
}
2630

2731
public function getErrorCode()
2832
{
2933
return $this->errorCode;
3034
}
35+
36+
public function getResponseMetadata()
37+
{
38+
return $this->responseMetadata;
39+
}
3140
}

src/HttpPlugin/SlackErrorPlugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
3333
return $response;
3434
}
3535

36-
throw new SlackErrorResponse($data['error']);
36+
$responseMetadata = null;
37+
if (isset($data['response_metadata'])) {
38+
$responseMetadata = $data['response_metadata'];
39+
}
40+
41+
throw new SlackErrorResponse($data['error'], $responseMetadata);
3742
});
3843
}
3944
}

0 commit comments

Comments
 (0)