Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
761a9f44
Commit
761a9f44
authored
Feb 01, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exception cleanup.
parent
6fcac324
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
104 additions
and
39 deletions
+104
-39
Application.php
framework/base/Application.php
+19
-2
ErrorHandler.php
framework/base/ErrorHandler.php
+16
-15
Exception.php
framework/base/Exception.php
+10
-2
HttpException.php
framework/base/HttpException.php
+4
-0
InvalidCallException.php
framework/base/InvalidCallException.php
+5
-2
InvalidConfigException.php
framework/base/InvalidConfigException.php
+5
-2
InvalidRequestException.php
framework/base/InvalidRequestException.php
+10
-2
InvalidRouteException.php
framework/base/InvalidRouteException.php
+10
-2
NotSupportedException.php
framework/base/NotSupportedException.php
+5
-2
UnknownMethodException.php
framework/base/UnknownMethodException.php
+5
-2
UnknownPropertyException.php
framework/base/UnknownPropertyException.php
+5
-2
Application.php
framework/console/Application.php
+1
-1
Exception.php
framework/db/Exception.php
+9
-5
No files found.
framework/base/Application.php
View file @
761a9f44
...
@@ -433,8 +433,7 @@ class Application extends Module
...
@@ -433,8 +433,7 @@ class Application extends Module
if
((
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
if
((
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
$handler
->
handle
(
$exception
);
$handler
->
handle
(
$exception
);
}
else
{
}
else
{
$message
=
YII_DEBUG
?
(
string
)
$exception
:
'Error: '
.
$exception
->
getMessage
()
.
"
\n
"
;
$this
->
renderException
(
$exception
);
echo
PHP_SAPI
===
'cli'
?
$message
:
'<pre>'
.
$message
.
'</pre>'
;
}
}
$this
->
end
(
1
);
$this
->
end
(
1
);
...
@@ -450,6 +449,24 @@ class Application extends Module
...
@@ -450,6 +449,24 @@ class Application extends Module
}
}
}
}
/**
* Renders an exception without using rich format.
* @param \Exception $exception the exception to be rendered.
*/
public
function
renderException
(
$exception
)
{
if
(
$exception
instanceof
Exception
&&
(
$exception
->
causedByUser
||
!
YII_DEBUG
))
{
$message
=
$exception
->
getName
()
.
': '
.
$exception
->
getMessage
();
}
else
{
$message
=
YII_DEBUG
?
(
string
)
$exception
:
'Error: '
.
$exception
->
getMessage
();
}
if
(
PHP_SAPI
)
{
echo
$message
.
"
\n
"
;
}
else
{
echo
'<pre>'
.
htmlspecialchars
(
$message
,
ENT_QUOTES
,
$this
->
charset
)
.
'</pre>'
;
}
}
// todo: to be polished
// todo: to be polished
protected
function
logException
(
$exception
)
protected
function
logException
(
$exception
)
{
{
...
...
framework/base/ErrorHandler.php
View file @
761a9f44
...
@@ -78,12 +78,20 @@ class ErrorHandler extends Component
...
@@ -78,12 +78,20 @@ class ErrorHandler extends Component
header
(
"HTTP/1.0
$errorCode
"
.
get_class
(
$exception
));
header
(
"HTTP/1.0
$errorCode
"
.
get_class
(
$exception
));
}
}
if
(
isset
(
$_SERVER
[
'HTTP_X_REQUESTED_WITH'
])
&&
$_SERVER
[
'HTTP_X_REQUESTED_WITH'
]
===
'XMLHttpRequest'
)
{
if
(
isset
(
$_SERVER
[
'HTTP_X_REQUESTED_WITH'
])
&&
$_SERVER
[
'HTTP_X_REQUESTED_WITH'
]
===
'XMLHttpRequest'
)
{
$this
->
renderAsText
(
$exception
);
\Yii
::
$application
->
renderException
(
$exception
);
}
else
{
}
else
{
$this
->
renderAsHtml
(
$exception
);
$view
=
new
View
(
$this
);
if
(
!
YII_DEBUG
||
$exception
instanceof
Exception
&&
$exception
->
causedByUser
)
{
$viewName
=
$this
->
errorView
;
}
else
{
$viewName
=
$this
->
exceptionView
;
}
echo
$view
->
render
(
$viewName
,
array
(
'exception'
=>
$exception
,
));
}
}
}
else
{
}
else
{
$this
->
renderAsText
(
$exception
);
\Yii
::
$application
->
renderException
(
$exception
);
}
}
}
}
...
@@ -245,21 +253,14 @@ class ErrorHandler extends Component
...
@@ -245,21 +253,14 @@ class ErrorHandler extends Component
/**
/**
* @param \Exception $exception
* @param \Exception $exception
*/
*/
public
function
renderAsText
(
$exception
)
{
if
(
YII_DEBUG
)
{
echo
$exception
;
}
else
{
echo
get_class
(
$exception
)
.
': '
.
$exception
->
getMessage
();
}
}
/**
* @param \Exception $exception
*/
public
function
renderAsHtml
(
$exception
)
public
function
renderAsHtml
(
$exception
)
{
{
$view
=
new
View
(
$this
);
$view
=
new
View
(
$this
);
if
(
!
YII_DEBUG
||
$exception
instanceof
Exception
&&
$exception
->
causedByUser
)
{
$viewName
=
$this
->
errorView
;
}
else
{
$viewName
=
$this
->
exceptionView
;
}
$name
=
!
YII_DEBUG
||
$exception
instanceof
HttpException
?
$this
->
errorView
:
$this
->
exceptionView
;
$name
=
!
YII_DEBUG
||
$exception
instanceof
HttpException
?
$this
->
errorView
:
$this
->
exceptionView
;
echo
$view
->
render
(
$name
,
array
(
echo
$view
->
render
(
$name
,
array
(
'exception'
=>
$exception
,
'exception'
=>
$exception
,
...
...
framework/base/Exception.php
View file @
761a9f44
...
@@ -18,8 +18,16 @@ namespace yii\base;
...
@@ -18,8 +18,16 @@ namespace yii\base;
class
Exception
extends
\Exception
class
Exception
extends
\Exception
{
{
/**
/**
* @var
string the user-friend name of this exception
* @var
boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
*/
public
$name
=
'Exception'
;
public
$causedByUser
=
false
;
/**
* @return string the user-friendly name of this exception
*/
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Exception'
);
}
}
}
framework/base/HttpException.php
View file @
761a9f44
...
@@ -25,6 +25,10 @@ class HttpException extends Exception
...
@@ -25,6 +25,10 @@ class HttpException extends Exception
* @var integer HTTP status code, such as 403, 404, 500, etc.
* @var integer HTTP status code, such as 403, 404, 500, etc.
*/
*/
public
$statusCode
;
public
$statusCode
;
/**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public
$causedByUser
=
true
;
/**
/**
* Constructor.
* Constructor.
...
...
framework/base/InvalidCallException.php
View file @
761a9f44
...
@@ -18,8 +18,11 @@ namespace yii\base;
...
@@ -18,8 +18,11 @@ namespace yii\base;
class
InvalidCallException
extends
\Exception
class
InvalidCallException
extends
\Exception
{
{
/**
/**
* @
var string the user-friend
name of this exception
* @
return string the user-friendly
name of this exception
*/
*/
public
$name
=
'Invalid Call Exception'
;
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Invalid Call'
);
}
}
}
framework/base/InvalidConfigException.php
View file @
761a9f44
...
@@ -18,8 +18,11 @@ namespace yii\base;
...
@@ -18,8 +18,11 @@ namespace yii\base;
class
InvalidConfigException
extends
\Exception
class
InvalidConfigException
extends
\Exception
{
{
/**
/**
* @
var string the user-friend
name of this exception
* @
return string the user-friendly
name of this exception
*/
*/
public
$name
=
'Invalid Configuration Exception'
;
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Invalid Configuration'
);
}
}
}
framework/base/InvalidRequestException.php
View file @
761a9f44
...
@@ -18,8 +18,16 @@ namespace yii\base;
...
@@ -18,8 +18,16 @@ namespace yii\base;
class
InvalidRequestException
extends
\Exception
class
InvalidRequestException
extends
\Exception
{
{
/**
/**
* @var
string the user-friend name of this exception
* @var
boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
*/
public
$name
=
'Invalid Request Exception'
;
public
$causedByUser
=
true
;
/**
* @return string the user-friendly name of this exception
*/
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Invalid Request'
);
}
}
}
framework/base/InvalidRouteException.php
View file @
761a9f44
...
@@ -18,8 +18,16 @@ namespace yii\base;
...
@@ -18,8 +18,16 @@ namespace yii\base;
class
InvalidRouteException
extends
\Exception
class
InvalidRouteException
extends
\Exception
{
{
/**
/**
* @var
string the user-friend name of this exception
* @var
boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
*/
public
$name
=
'Invalid Route Exception'
;
public
$causedByUser
=
true
;
/**
* @return string the user-friendly name of this exception
*/
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Invalid Route'
);
}
}
}
framework/base/NotSupportedException.php
View file @
761a9f44
...
@@ -18,8 +18,11 @@ namespace yii\base;
...
@@ -18,8 +18,11 @@ namespace yii\base;
class
NotSupportedException
extends
\Exception
class
NotSupportedException
extends
\Exception
{
{
/**
/**
* @
var string the user-friend
name of this exception
* @
return string the user-friendly
name of this exception
*/
*/
public
$name
=
'Not Supported Exception'
;
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Not Supported'
);
}
}
}
framework/base/UnknownMethodException.php
View file @
761a9f44
...
@@ -18,8 +18,11 @@ namespace yii\base;
...
@@ -18,8 +18,11 @@ namespace yii\base;
class
UnknownMethodException
extends
\Exception
class
UnknownMethodException
extends
\Exception
{
{
/**
/**
* @
var string the user-friend
name of this exception
* @
return string the user-friendly
name of this exception
*/
*/
public
$name
=
'Unknown Method Exception'
;
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Unknown Method'
);
}
}
}
framework/base/UnknownPropertyException.php
View file @
761a9f44
...
@@ -18,8 +18,11 @@ namespace yii\base;
...
@@ -18,8 +18,11 @@ namespace yii\base;
class
UnknownPropertyException
extends
\Exception
class
UnknownPropertyException
extends
\Exception
{
{
/**
/**
* @
var string the user-friend
name of this exception
* @
return string the user-friendly
name of this exception
*/
*/
public
$name
=
'Unknown Property Exception'
;
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Unknown Property'
);
}
}
}
framework/console/Application.php
View file @
761a9f44
...
@@ -112,7 +112,7 @@ class Application extends \yii\base\Application
...
@@ -112,7 +112,7 @@ class Application extends \yii\base\Application
try
{
try
{
return
parent
::
runAction
(
$route
,
$params
);
return
parent
::
runAction
(
$route
,
$params
);
}
catch
(
InvalidRouteException
$e
)
{
}
catch
(
InvalidRouteException
$e
)
{
echo
"
\n
Error: unknown command
\"
$route
\"
.
\n
"
;
echo
"Error: unknown command
\"
$route
\"
.
\n
"
;
return
1
;
return
1
;
}
}
}
}
...
...
framework/db/Exception.php
View file @
761a9f44
...
@@ -18,11 +18,6 @@ namespace yii\db;
...
@@ -18,11 +18,6 @@ namespace yii\db;
class
Exception
extends
\yii\base\Exception
class
Exception
extends
\yii\base\Exception
{
{
/**
/**
* @var string the user-friend name of this exception
*/
public
$name
=
'Database Exception'
;
/**
* @var mixed the error info provided by a PDO exception. This is the same as returned
* @var mixed the error info provided by a PDO exception. This is the same as returned
* by [PDO::errorInfo](http://www.php.net/manual/en/pdo.errorinfo.php).
* by [PDO::errorInfo](http://www.php.net/manual/en/pdo.errorinfo.php).
*/
*/
...
@@ -39,4 +34,12 @@ class Exception extends \yii\base\Exception
...
@@ -39,4 +34,12 @@ class Exception extends \yii\base\Exception
$this
->
errorInfo
=
$errorInfo
;
$this
->
errorInfo
=
$errorInfo
;
parent
::
__construct
(
$message
,
$code
);
parent
::
__construct
(
$message
,
$code
);
}
}
/**
* @return string the user-friendly name of this exception
*/
public
function
getName
()
{
return
\Yii
::
t
(
'yii'
,
'Database Exception'
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment