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
46d92856
Commit
46d92856
authored
Mar 03, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated error code.
parent
7a04dbaa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
13 deletions
+16
-13
rest.md
docs/guide/rest.md
+11
-8
Controller.php
framework/rest/Controller.php
+4
-4
Serializer.php
framework/rest/Serializer.php
+1
-1
No files found.
docs/guide/rest.md
View file @
46d92856
...
...
@@ -144,17 +144,20 @@ HTTP Status Code Summary
------------------------
*
`200`
: OK. Everything worked as expected.
*
`201`
: A
data item was successfully created. Please check the
`Location`
header for the URL to access the new data item.
*
`204`
: A data item was successfully deleted
.
*
`
304`
: Data not modified. You can use cached data
.
*
`
400`
: Bad request. This could be caused by various reasons from the user side, such as invalid content type request,
invalid API version number, or data validation failure. If it is data validation failure, please check
the response body for error messages
.
*
`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 is handled successfully and the response contains no body content (like a
`DELETE`
request)
.
*
`
304`
: Resource 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
.
*
`401`
: No valid API access token is provided.
*
`403`
: The authenticated user is not allowed to access the specified API endpoint.
*
`404`
: The requested
item
does not exist.
*
`404`
: The requested
resource
does not exist.
*
`405`
: Method not allowed. Please check the
`Allow`
header for allowed HTTP methods.
*
`500`
: Internal server error.
*
`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 is rejected due to rate limiting.
*
`500`
: Internal server error. This could be caused by internal program errors.
Data Formatting
...
...
framework/rest/Controller.php
View file @
46d92856
...
...
@@ -8,9 +8,9 @@
namespace
yii\rest
;
use
Yii
;
use
yii\web\BadRequestHttpException
;
use
yii\web\Response
;
use
yii\web\UnauthorizedHttpException
;
use
yii\web\UnsupportedMediaTypeHttpException
;
use
yii\web\VerbFilter
;
/**
...
...
@@ -124,7 +124,7 @@ class Controller extends \yii\web\Controller
/**
* Resolves the response format and the API version number.
* @throws
BadRequest
HttpException
* @throws
UnsupportedMediaType
HttpException
*/
protected
function
resolveFormatAndVersion
()
{
...
...
@@ -142,7 +142,7 @@ class Controller extends \yii\web\Controller
if
(
in_array
(
$params
[
self
::
HEADER_VERSION
],
$this
->
supportedVersions
,
true
))
{
$this
->
version
=
$params
[
self
::
HEADER_VERSION
];
}
else
{
throw
new
BadRequest
HttpException
(
'You are requesting an invalid version number.'
);
throw
new
UnsupportedMediaType
HttpException
(
'You are requesting an invalid version number.'
);
}
}
return
;
...
...
@@ -150,7 +150,7 @@ class Controller extends \yii\web\Controller
}
if
(
!
isset
(
$types
[
'*/*'
]))
{
throw
new
BadRequestHttpException
(
'None of your requested content types is vali
d.'
);
throw
new
UnsupportedMediaTypeHttpException
(
'None of your requested content types is supporte
d.'
);
}
}
...
...
framework/rest/Serializer.php
View file @
46d92856
...
...
@@ -126,7 +126,7 @@ class Serializer extends Component
*/
protected
function
serializeModelErrors
(
$model
)
{
$this
->
response
->
setStatusCode
(
4
00
,
'Data Validation Failure
'
);
$this
->
response
->
setStatusCode
(
4
22
,
'Data Validation Failed.
'
);
$result
=
[];
foreach
(
$model
->
getFirstErrors
()
as
$name
=>
$message
)
{
$result
[]
=
[
...
...
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