Skip to content

Commit cb806e0

Browse files
committed
Exception improvement: separate human beings' error and machine's error
- LogicException is a built-in exception class - Pre-defined message for ActionNotFoundException - Remove unnecessary constructor override
1 parent d6a1172 commit cb806e0

File tree

7 files changed

+15
-44
lines changed

7 files changed

+15
-44
lines changed

src/ActionKit/Exception/ActionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ActionException extends Exception
66
{
77
public $action;
88

9-
public function __construct( $msg , $action )
9+
public function __construct($msg, $action)
1010
{
1111
$this->action = $action;
1212
parent::__construct($msg);
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22
namespace ActionKit\Exception;
3-
use Exception;
3+
use LogicException;
44

5-
class ActionNotFoundException extends Exception
5+
class ActionNotFoundException extends LogicException
66
{
7+
public $actionClass;
78

8-
public function __construct( $msg )
9-
{
10-
parent::__construct($msg);
9+
public function __construct($actionClass) {
10+
$this->actionClass = $actionClass;
11+
parent::__construct("Action class '$actionClass' not found, you might need to setup action autoloader or register the action template");
1112
}
1213
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?php
22
namespace ActionKit\Exception;
3-
use Exception;
3+
use LogicException;
44

5-
class InvalidActionNameException extends Exception
5+
class InvalidActionNameException extends LogicException
66
{
7-
8-
public function __construct( $msg )
9-
{
10-
parent::__construct($msg);
11-
}
127
}

src/ActionKit/Exception/LogicException.php

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?php
22
namespace ActionKit\Exception;
3-
use Exception;
3+
use RuntimeException;
44

5-
class UnableToCreateActionException extends Exception
5+
class UnableToCreateActionException extends RuntimeException
66
{
7-
8-
public function __construct( $msg )
9-
{
10-
parent::__construct($msg);
11-
}
127
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?php
22
namespace ActionKit\Exception;
3-
use Exception;
3+
use RuntimeException;
44

5-
class UnableToWriteCacheException extends Exception
5+
class UnableToWriteCacheException extends RuntimeException
66
{
7-
8-
public function __construct( $msg )
9-
{
10-
parent::__construct($msg);
11-
}
127
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<?php
22
namespace ActionKit\Exception;
3-
use Exception;
3+
use LogicException;
44

5-
class UndefinedTemplateException extends Exception
5+
class UndefinedTemplateException extends LogicException
66
{
7-
public function __construct( $msg)
8-
{
9-
parent::__construct($msg);
10-
}
117
}

0 commit comments

Comments
 (0)