-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
42 lines (38 loc) · 1.36 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package coap
import "errors"
var (
ErrTimeout = errors.New("coap: timeout")
ErrBadRequest = errors.New("coap: bad request")
ErrNotFound = errors.New("coap: not found")
ErrUnauthorized = errors.New("coap: not authorized")
ErrMethodNotAllowed = errors.New("coap: method not allowed")
ErrEncodingNotAcceptable = errors.New("coap: encoding not acceptable")
ErrInternalServerError = errors.New("coap: internal server error")
ErrInvalidTokenLen = errors.New("coap: invalid token length")
ErrOptionTooLong = errors.New("coap: option is too long")
ErrOptionGapTooLarge = errors.New("coap: option gap too large")
)
func RspCodeToError(code COAPCode) error {
if code < 100 {
return nil
}
switch code {
case RspCodeBadRequest:
return ErrBadRequest
case RspCodeNotFound:
return ErrNotFound
case RspCodeUnauthorized:
return ErrUnauthorized
case RspCodeMethodNotAllowed:
return ErrMethodNotAllowed
case RspCodeNotAcceptable:
return ErrEncodingNotAcceptable
case RspCodeInternalServerError:
return ErrInternalServerError
default:
return errors.New("coap: other error " + code.String())
}
}