Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a52b2163
Commit
a52b2163
authored
Jan 12, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MethodNotSupported error
parent
6cd37637
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
errors.go
pkg/api/errors/errors.go
+19
-0
errors_test.go
pkg/api/errors/errors_test.go
+12
-0
types.go
pkg/api/types.go
+5
-0
No files found.
pkg/api/errors/errors.go
View file @
a52b2163
...
@@ -159,6 +159,19 @@ func NewBadRequest(reason string) error {
...
@@ -159,6 +159,19 @@ func NewBadRequest(reason string) error {
}}
}}
}
}
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
func
NewMethodNotSupported
(
kind
,
action
string
)
error
{
return
&
StatusError
{
api
.
Status
{
Status
:
api
.
StatusFailure
,
Code
:
http
.
StatusMethodNotAllowed
,
Reason
:
api
.
StatusReasonMethodNotAllowed
,
Details
:
&
api
.
StatusDetails
{
Kind
:
kind
,
},
Message
:
fmt
.
Sprintf
(
"%s is not supported on resources of kind %q"
,
action
,
kind
),
}}
}
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
func
NewInternalError
(
err
error
)
error
{
func
NewInternalError
(
err
error
)
error
{
return
&
StatusError
{
api
.
Status
{
return
&
StatusError
{
api
.
Status
{
...
@@ -192,6 +205,12 @@ func IsInvalid(err error) bool {
...
@@ -192,6 +205,12 @@ func IsInvalid(err error) bool {
return
reasonForError
(
err
)
==
api
.
StatusReasonInvalid
return
reasonForError
(
err
)
==
api
.
StatusReasonInvalid
}
}
// IsMethodNotSupported determines if the err is an error which indicates the provided action could not
// be performed because it is not supported by the server.
func
IsMethodNotSupported
(
err
error
)
bool
{
return
reasonForError
(
err
)
==
api
.
StatusReasonMethodNotAllowed
}
// IsBadRequest determines if err is an error which indicates that the request is invalid.
// IsBadRequest determines if err is an error which indicates that the request is invalid.
func
IsBadRequest
(
err
error
)
bool
{
func
IsBadRequest
(
err
error
)
bool
{
return
reasonForError
(
err
)
==
api
.
StatusReasonBadRequest
return
reasonForError
(
err
)
==
api
.
StatusReasonBadRequest
...
...
pkg/api/errors/errors_test.go
View file @
a52b2163
...
@@ -40,6 +40,12 @@ func TestErrorNew(t *testing.T) {
...
@@ -40,6 +40,12 @@ func TestErrorNew(t *testing.T) {
if
IsInvalid
(
err
)
{
if
IsInvalid
(
err
)
{
t
.
Errorf
(
"expected to not be %s"
,
api
.
StatusReasonInvalid
)
t
.
Errorf
(
"expected to not be %s"
,
api
.
StatusReasonInvalid
)
}
}
if
IsBadRequest
(
err
)
{
t
.
Errorf
(
"expected to not be %s"
,
api
.
StatusReasonBadRequest
)
}
if
IsMethodNotSupported
(
err
)
{
t
.
Errorf
(
"expected to not be %s"
,
api
.
StatusReasonMethodNotAllowed
)
}
if
!
IsConflict
(
NewConflict
(
"test"
,
"2"
,
errors
.
New
(
"message"
)))
{
if
!
IsConflict
(
NewConflict
(
"test"
,
"2"
,
errors
.
New
(
"message"
)))
{
t
.
Errorf
(
"expected to be conflict"
)
t
.
Errorf
(
"expected to be conflict"
)
...
@@ -50,6 +56,12 @@ func TestErrorNew(t *testing.T) {
...
@@ -50,6 +56,12 @@ func TestErrorNew(t *testing.T) {
if
!
IsInvalid
(
NewInvalid
(
"test"
,
"2"
,
nil
))
{
if
!
IsInvalid
(
NewInvalid
(
"test"
,
"2"
,
nil
))
{
t
.
Errorf
(
"expected to be %s"
,
api
.
StatusReasonInvalid
)
t
.
Errorf
(
"expected to be %s"
,
api
.
StatusReasonInvalid
)
}
}
if
!
IsBadRequest
(
NewBadRequest
(
"reason"
))
{
t
.
Errorf
(
"expected to be %s"
,
api
.
StatusReasonBadRequest
)
}
if
!
IsMethodNotSupported
(
NewMethodNotSupported
(
"foo"
,
"delete"
))
{
t
.
Errorf
(
"expected to be %s"
,
api
.
StatusReasonMethodNotAllowed
)
}
}
}
func
TestNewInvalid
(
t
*
testing
.
T
)
{
func
TestNewInvalid
(
t
*
testing
.
T
)
{
...
...
pkg/api/types.go
View file @
a52b2163
...
@@ -931,6 +931,11 @@ const (
...
@@ -931,6 +931,11 @@ const (
// data was invalid. API calls that return BadRequest can never succeed.
// data was invalid. API calls that return BadRequest can never succeed.
StatusReasonBadRequest
StatusReason
=
"BadRequest"
StatusReasonBadRequest
StatusReason
=
"BadRequest"
// StatusReasonMethodNotAllowed means that the action the client attempted to perform on the
// resource was not supported by the code - for instance, attempting to delete a resource that
// can only be created. API calls that return MethodNotAllowed can never succeed.
StatusReasonMethodNotAllowed
StatusReason
=
"MethodNotAllowed"
// StatusReasonInternalError indicates that an internal error occurred, it is unexpected
// StatusReasonInternalError indicates that an internal error occurred, it is unexpected
// and the outcome of the call is unknown.
// and the outcome of the call is unknown.
// Details (optional):
// Details (optional):
...
...
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