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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
edd29302
Commit
edd29302
authored
Aug 18, 2014
by
Larry Ullman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Light edits
parent
2aba4346
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
rest-error-handling.md
docs/guide/rest-error-handling.md
+12
-12
No files found.
docs/guide/rest-error-handling.md
View file @
edd29302
...
...
@@ -2,12 +2,12 @@ Error Handling
==============
When handling a RESTful API request, if there is an error in the user request or if something unexpected
happens on the server, you may simply throw an exception to notify the user that something w
rong has happened
.
If you can identify the cause of the error (e.g. the requested resource does not exist), you should
consider throwing an exception
with a proper HTTP status code (e.g.
[
[yii\web\NotFoundHttpException
]
]
represent
ing a 404 HTTP status code). Yii will send the response
with the corresponding HTTP status
code and text.
It will also include in the response body
the serialized representation of the
exception
. For example,
happens on the server, you may simply throw an exception to notify the user that something w
ent wrong
.
If you can identify the cause of the error (e.g.
,
the requested resource does not exist), you should
consider throwing an exception
along with a proper HTTP status code (e.g.,
[
[yii\web\NotFoundHttpException
]
]
represent
s a 404 status code). Yii will send the response along
with the corresponding HTTP status
code and text.
Yii will also include
the serialized representation of the
exception
in the response body. For example:
```
HTTP/1.1 404 Not Found
...
...
@@ -30,15 +30,15 @@ The following list summarizes the HTTP status code that are used by the Yii REST
*
`200`
: OK. Everything worked as expected.
*
`201`
: A resource was successfully created in response to a
`POST`
request. The
`Location`
header
contains the URL pointing to the newly created resource.
*
`204`
: The request
i
s handled successfully and the response contains no body content (like a
`DELETE`
request).
*
`304`
:
R
esource was not modified. You can use the cached version.
*
`400`
: Bad request. This could be caused by various
reasons from the user side, such as
invalid JSON
data in the request body, invalid action parameters, etc.
*
`204`
: The request
wa
s handled successfully and the response contains no body content (like a
`DELETE`
request).
*
`304`
:
The r
esource was not modified. You can use the cached version.
*
`400`
: Bad request. This could be caused by various
actions by the user, such as providing
invalid JSON
data in the request body,
providing
invalid action parameters, etc.
*
`401`
: Authentication failed.
*
`403`
: The authenticated user is not allowed to access the specified API endpoint.
*
`404`
: The requested resource does not exist.
*
`405`
: Method not allowed. Please check the
`Allow`
header for allowed HTTP methods.
*
`405`
: Method not allowed. Please check the
`Allow`
header for
the
allowed HTTP methods.
*
`415`
: Unsupported media type. The requested content type or version number is invalid.
*
`422`
: Data validation failed (in response to a
`POST`
request, for example). Please check the response body for detailed error messages.
*
`429`
: Too many requests. The request
i
s rejected due to rate limiting.
*
`429`
: Too many requests. The request
wa
s rejected due to rate limiting.
*
`500`
: Internal server error. This could be caused by internal program errors.
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