PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Exceptions / YatraException.php

YatraException.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Exceptions/YatraException.php

80 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Exceptions;
6
7 use Exception;
8
9 /**
10 * Base Yatra Exception
11 *
12 * Provides structured error handling with error codes and context
13 */
14 class YatraException extends Exception
15 {
16 /**
17 * @var array Additional context data
18 */
19 protected array $context = [];
20
21 /**
22 * @var string Error code for API responses
23 */
24 protected string $errorCode = 'yatra_error';
25
26 public function __construct(string $message = '', int $code = 0, ?Exception $previous = null, array $context = [])
27 {
28 parent::__construct($message, $code, $previous);
29 $this->context = $context;
30 }
31
32 /**
33 * Get error context
34 */
35 public function getContext(): array
36 {
37 return $this->context;
38 }
39
40 /**
41 * Get API error code
42 */
43 public function getErrorCode(): string
44 {
45 return $this->errorCode;
46 }
47
48 /**
49 * Set error context
50 */
51 public function setContext(array $context): self
52 {
53 $this->context = $context;
54 return $this;
55 }
56
57 /**
58 * Add context data
59 */
60 public function addContext(string $key, $value): self
61 {
62 $this->context[$key] = $value;
63 return $this;
64 }
65
66 /**
67 * Convert to array for API responses
68 */
69 public function toArray(): array
70 {
71 return [
72 'error_code' => $this->getErrorCode(),
73 'message' => $this->getMessage(),
74 'context' => $this->getContext(),
75 'file' => $this->getFile(),
76 'line' => $this->getLine(),
77 ];
78 }
79 }
80