Skip to content

Commit 675f4b1

Browse files
author
Nur Arif Prihutomo
committed
feat: create Package Exceptions
1 parent 4f865dc commit 675f4b1

9 files changed

+808
-0
lines changed

src/Exceptions/AccessException.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Exceptions
8+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.1
11+
* @link https://github.com/brispot
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Brispot\PhpLib\Exceptions;
17+
18+
use Exception;
19+
use Brispot\PhpLib\Exceptions\ExceptionInterface;
20+
21+
/**
22+
* Class AccessException
23+
*
24+
* @category Library
25+
* @package Exceptions
26+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
27+
* @license https://mit-license.org/ MIT License
28+
* @link https://github.com/brispot
29+
*/
30+
class AccessException extends Exception implements ExceptionInterface
31+
{
32+
/* Properties */
33+
private string $errorCode;
34+
private string $errorMessage;
35+
private int $httpCode;
36+
private mixed $data;
37+
38+
/**
39+
* Create a new AccessException instance.
40+
*
41+
* @param string $message Message of Exception
42+
* @param mixed $data Optional data when exception has response data
43+
*
44+
* @return void
45+
*/
46+
public function __construct(string $message = 'Akses tidak diijinkan', mixed $data = null)
47+
{
48+
$this->errorCode = 'X1';
49+
$this->errorMessage = $message;
50+
$this->httpCode = 403;
51+
$this->data = $data;
52+
parent::__construct($message, 1, null);
53+
}
54+
55+
/**
56+
* Get attribute errorCode
57+
*
58+
* @return string
59+
*/
60+
public function getErrorCode(): string
61+
{
62+
return $this->errorCode;
63+
}
64+
65+
/**
66+
* Get attribute errorMessage
67+
*
68+
* @return string
69+
*/
70+
public function getErrorMessage(): string
71+
{
72+
return $this->errorMessage;
73+
}
74+
75+
/**
76+
* Get attribute httpCode
77+
*
78+
* @return int
79+
*/
80+
public function getHttpCode(): int
81+
{
82+
return $this->httpCode;
83+
}
84+
85+
/**
86+
* Get attribute data
87+
*
88+
* @return mixed
89+
*/
90+
public function getData(): mixed
91+
{
92+
return $this->data;
93+
}
94+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Exceptions
8+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.1
11+
* @link https://github.com/brispot
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Brispot\PhpLib\Exceptions;
17+
18+
use Exception;
19+
use Brispot\PhpLib\Exceptions\ExceptionInterface;
20+
21+
/**
22+
* Class DataNotFoundException
23+
*
24+
* @category Library
25+
* @package Exceptions
26+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
27+
* @license https://mit-license.org/ MIT License
28+
* @link https://github.com/brispot
29+
*/
30+
class DataNotFoundException extends Exception implements ExceptionInterface
31+
{
32+
/* Properties */
33+
private string $errorCode;
34+
private string $errorMessage;
35+
private int $httpCode;
36+
private mixed $data;
37+
38+
/**
39+
* Create a new DataNotFoundException instance.
40+
*
41+
* @param string $message Message of Exception
42+
* @param mixed $data Optional data when exception has response data
43+
*
44+
* @return void
45+
*/
46+
public function __construct(string $message = 'Data tidak ditemukan', mixed $data = null)
47+
{
48+
$this->errorCode = '02';
49+
$this->errorMessage = $message;
50+
$this->httpCode = 200;
51+
$this->data = $data;
52+
parent::__construct($message, 2, null);
53+
}
54+
55+
/**
56+
* Get attribute errorCode
57+
*
58+
* @return string
59+
*/
60+
public function getErrorCode(): string
61+
{
62+
return $this->errorCode;
63+
}
64+
65+
/**
66+
* Get attribute errorMessage
67+
*
68+
* @return string
69+
*/
70+
public function getErrorMessage(): string
71+
{
72+
return $this->errorMessage;
73+
}
74+
75+
/**
76+
* Get attribute httpCode
77+
*
78+
* @return int
79+
*/
80+
public function getHttpCode(): int
81+
{
82+
return $this->httpCode;
83+
}
84+
85+
/**
86+
* Get attribute data
87+
*
88+
* @return mixed
89+
*/
90+
public function getData(): mixed
91+
{
92+
return $this->data;
93+
}
94+
}

src/Exceptions/ExceptionInterface.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Exceptions
8+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.1
11+
* @link https://github.com/brispot
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Brispot\PhpLib\Exceptions;
17+
18+
/**
19+
* Interface ExceptionInterface for all implementation Exception Class
20+
*
21+
* @category Library
22+
* @package Exceptions
23+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
24+
* @license https://mit-license.org/ MIT License
25+
* @link https://github.com/brispot
26+
*/
27+
interface ExceptionInterface
28+
{
29+
/**
30+
* Get attribute errorCode
31+
*
32+
* @return string
33+
*/
34+
public function getErrorCode(): string;
35+
36+
/**
37+
* Get attribute errorMessage
38+
*
39+
* @return string
40+
*/
41+
public function getErrorMessage(): string;
42+
43+
/**
44+
* Get attribute httpCode
45+
*
46+
* @return int
47+
*/
48+
public function getHttpCode(): int;
49+
50+
/**
51+
* Get attribute data
52+
*
53+
* @return mixed
54+
*/
55+
public function getData(): mixed;
56+
}

src/Exceptions/HeaderException.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Exceptions
8+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.1
11+
* @link https://github.com/brispot
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Brispot\PhpLib\Exceptions;
17+
18+
use Exception;
19+
use Brispot\PhpLib\Exceptions\ExceptionInterface;
20+
21+
/**
22+
* Class HeaderException
23+
*
24+
* @category Library
25+
* @package Exceptions
26+
* @author Nur Arif Prihutomo <nur.arif@corp.bri.co.id>
27+
* @license https://mit-license.org/ MIT License
28+
* @link https://github.com/brispot
29+
*/
30+
class HeaderException extends Exception implements ExceptionInterface
31+
{
32+
/* Properties */
33+
private string $errorCode;
34+
private string $errorMessage;
35+
private int $httpCode;
36+
private mixed $data;
37+
38+
/**
39+
* Create a new HeaderException instance.
40+
*
41+
* @param string $message Message of Exception
42+
* @param mixed $data Optional data when exception has response data
43+
*
44+
* @return void
45+
*/
46+
public function __construct(string $message = 'Header Request tidak valid', mixed $data = null)
47+
{
48+
$this->errorCode = 'X0';
49+
$this->errorMessage = $message;
50+
$this->httpCode = 400;
51+
$this->data = $data;
52+
parent::__construct($message, 1, null);
53+
}
54+
55+
/**
56+
* Get attribute errorCode
57+
*
58+
* @return string
59+
*/
60+
public function getErrorCode(): string
61+
{
62+
return $this->errorCode;
63+
}
64+
65+
/**
66+
* Get attribute errorMessage
67+
*
68+
* @return string
69+
*/
70+
public function getErrorMessage(): string
71+
{
72+
return $this->errorMessage;
73+
}
74+
75+
/**
76+
* Get attribute httpCode
77+
*
78+
* @return int
79+
*/
80+
public function getHttpCode(): int
81+
{
82+
return $this->httpCode;
83+
}
84+
85+
/**
86+
* Get attribute data
87+
*
88+
* @return mixed
89+
*/
90+
public function getData(): mixed
91+
{
92+
return $this->data;
93+
}
94+
}

0 commit comments

Comments
 (0)