-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
32 lines (29 loc) · 1.01 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
package ws
import (
"net/http"
"github.com/pixlise/core/v4/core/errorwithstatus"
protos "github.com/pixlise/core/v4/generated-protos"
)
func makeRespStatus(err error) protos.ResponseStatus {
switch e := err.(type) {
case errorwithstatus.Error:
// Here we're expecting to be given the protos.ResponseStatus values, but if it's not one of these
// we say WS_SERVER_ERROR
status := e.Status()
if status <= int(protos.ResponseStatus_WS_UNDEFINED.Number()) || status > int(protos.ResponseStatus_WS_SERVER_ERROR.Number()) {
// Try to map errors we'd send back via HTTP
if status == http.StatusNotFound {
return protos.ResponseStatus_WS_NOT_FOUND
} else if status == http.StatusBadRequest {
return protos.ResponseStatus_WS_BAD_REQUEST
} else if status == http.StatusUnauthorized {
return protos.ResponseStatus_WS_NO_PERMISSION
} else {
return protos.ResponseStatus_WS_SERVER_ERROR
}
}
return protos.ResponseStatus(status)
default:
return protos.ResponseStatus_WS_SERVER_ERROR
}
}