Browse code

Added README.md appinfo/info.xml appinfo/signature.json lib/Controller/AuthorApiController.php and the providers directory

DoubleBastionAdmin authored on 20/08/2022 16:33:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,69 @@
1
+<?php
2
+
3
+namespace Telnyx\Error;
4
+
5
+use Exception;
6
+
7
+abstract class Base extends Exception
8
+{
9
+    public function __construct(
10
+        $message,
11
+        $httpStatus = null,
12
+        $httpBody = null,
13
+        $jsonBody = null,
14
+        $httpHeaders = null
15
+    ) {
16
+        parent::__construct($message);
17
+        $this->httpStatus = $httpStatus;
18
+        $this->httpBody = $httpBody;
19
+        $this->jsonBody = $jsonBody;
20
+        $this->httpHeaders = $httpHeaders;
21
+        $this->requestId = null;
22
+
23
+        // TODO: make this a proper constructor argument in the next major
24
+        //       release.
25
+        $this->telnyxCode = isset($jsonBody["error"]["code"]) ? $jsonBody["error"]["code"] : null;
26
+
27
+        if ($httpHeaders && isset($httpHeaders['Request-Id'])) {
28
+            $this->requestId = $httpHeaders['Request-Id'];
29
+        }
30
+    }
31
+
32
+    public function getTelnyxCode()
33
+    {
34
+        return $this->telnyxCode;
35
+    }
36
+
37
+    public function getHttpStatus()
38
+    {
39
+        return $this->httpStatus;
40
+    }
41
+
42
+    public function getHttpBody()
43
+    {
44
+        return $this->httpBody;
45
+    }
46
+
47
+    public function getJsonBody()
48
+    {
49
+        return $this->jsonBody;
50
+    }
51
+
52
+    public function getHttpHeaders()
53
+    {
54
+        return $this->httpHeaders;
55
+    }
56
+
57
+    public function getRequestId()
58
+    {
59
+        return $this->requestId;
60
+    }
61
+
62
+    public function __toString()
63
+    {
64
+        $id = $this->requestId ? " from API request '{$this->requestId}'": "";
65
+        $message = explode("\n", parent::__toString());
66
+        $message[0] .= $id;
67
+        return implode("\n", $message);
68
+    }
69
+}