| 1 |
package centrifuge |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/centrifugal/protocol" |
| 7 |
) |
| 8 |
|
| 9 |
var _ error = (*Error)(nil) |
| 10 |
|
| 11 |
// Error represents client reply error. |
| 12 |
type Error struct { |
| 13 |
Code uint32 |
| 14 |
Message string |
| 15 |
} |
| 16 |
|
| 17 |
func (e *Error) toProto() *protocol.Error { |
| 18 |
return &protocol.Error{ |
| 19 |
Code: e.Code, |
| 20 |
Message: e.Message, |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
func (e Error) Error() string { |
| 25 |
return fmt.Sprintf("%d: %s", e.Code, e.Message) |
| 26 |
} |
| 27 |
|
| 28 |
// Here we define well-known errors that can be used in client protocol |
| 29 |
// replies. |
| 30 |
// Library user can define own application specific errors. When define new |
| 31 |
// custom error it is recommended to use error codes > 1000 assuming that |
| 32 |
// codes in interval 0-999 reserved by Centrifuge. |
| 33 |
var ( |
| 34 |
// ErrorInternal means server error, if returned this is a signal |
| 35 |
// that something went wrong with server itself and client most probably |
| 36 |
// not guilty. |
| 37 |
ErrorInternal = &Error{ |
| 38 |
Code: 100, |
| 39 |
Message: "internal server error", |
| 40 |
} |
| 41 |
// ErrorUnauthorized says that request is unauthorized. |
| 42 |
ErrorUnauthorized = &Error{ |
| 43 |
Code: 101, |
| 44 |
Message: "unauthorized", |
| 45 |
} |
| 46 |
// ErrorUnknownChannel means that channel name does not exist. |
| 47 |
ErrorUnknownChannel = &Error{ |
| 48 |
Code: 102, |
| 49 |
Message: "unknown channel", |
| 50 |
} |
| 51 |
// ErrorPermissionDenied means that access to resource not allowed. |
| 52 |
ErrorPermissionDenied = &Error{ |
| 53 |
Code: 103, |
| 54 |
Message: "permission denied", |
| 55 |
} |
| 56 |
// ErrorMethodNotFound means that method sent in command does not exist. |
| 57 |
ErrorMethodNotFound = &Error{ |
| 58 |
Code: 104, |
| 59 |
Message: "method not found", |
| 60 |
} |
| 61 |
// ErrorAlreadySubscribed returned when client wants to subscribe on channel |
| 62 |
// it already subscribed to. |
| 63 |
ErrorAlreadySubscribed = &Error{ |
| 64 |
Code: 105, |
| 65 |
Message: "already subscribed", |
| 66 |
} |
| 67 |
// ErrorLimitExceeded says that some sort of limit exceeded, server logs should |
| 68 |
// give more detailed information. See also ErrorTooManyRequests which is more |
| 69 |
// specific for rate limiting purposes. |
| 70 |
ErrorLimitExceeded = &Error{ |
| 71 |
Code: 106, |
| 72 |
Message: "limit exceeded", |
| 73 |
} |
| 74 |
// ErrorBadRequest says that server can not process received |
| 75 |
// data because it is malformed. Retrying request does not make sense. |
| 76 |
ErrorBadRequest = &Error{ |
| 77 |
Code: 107, |
| 78 |
Message: "bad request", |
| 79 |
} |
| 80 |
// ErrorNotAvailable means that resource is not enabled. |
| 81 |
ErrorNotAvailable = &Error{ |
| 82 |
Code: 108, |
| 83 |
Message: "not available", |
| 84 |
} |
| 85 |
// ErrorTokenExpired indicates that connection token expired. |
| 86 |
ErrorTokenExpired = &Error{ |
| 87 |
Code: 109, |
| 88 |
Message: "token expired", |
| 89 |
} |
| 90 |
// ErrorExpired indicates that connection expired (no token involved). |
| 91 |
ErrorExpired = &Error{ |
| 92 |
Code: 110, |
| 93 |
Message: "expired", |
| 94 |
} |
| 95 |
// ErrorTooManyRequests means that server rejected request due to |
| 96 |
// its rate limiting strategies. |
| 97 |
ErrorTooManyRequests = &Error{ |
| 98 |
Code: 111, |
| 99 |
Message: "too many requests", |
| 100 |
} |
| 101 |
// ErrorUnrecoverablePosition means that stream does not contain required |
| 102 |
// range of publications to fulfill a history query. This can be happen to |
| 103 |
// expiration, size limitation or due to wrong epoch. |
| 104 |
ErrorUnrecoverablePosition = &Error{ |
| 105 |
Code: 112, |
| 106 |
Message: "unrecoverable position", |
| 107 |
} |
| 108 |
) |