/
errors.go
47 lines (34 loc) 路 1.45 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
43
44
45
46
47
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package auth
import (
"net/http"
)
// Failure adds a behavioural hint to an Error.
type Failure interface {
error
// SuggestedResponseCode gives a HTTP status code.
SuggestedResponseCode() int
}
// badRequestError is returned on formal errors.
type badRequestError string
// Error implements the error interface.
func (e badRequestError) Error() string { return string(e) }
// SuggestedResponseCode implements the Failure interface.
func (e badRequestError) SuggestedResponseCode() int { return http.StatusBadRequest }
// unauthorizedError is given when the credentials have not been found in a database.
//
// The client should try again using different credentials.
type unauthorizedError string
// Error implements the error interface.
func (e unauthorizedError) Error() string { return string(e) }
// SuggestedResponseCode implements the Failure interface.
func (e unauthorizedError) SuggestedResponseCode() int { return http.StatusUnauthorized }
// forbiddenError is return when the credentials have been found, but don't grant the necessary rights.
//
// The client should not try again.
type forbiddenError string
// Error implements the error interface.
func (e forbiddenError) Error() string { return string(e) }
// SuggestedResponseCode implements the Failure interface.
func (e forbiddenError) SuggestedResponseCode() int { return http.StatusForbidden }