]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blame - api/const.go
Load credentials only when user requests it.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / api / const.go
CommitLineData
7a9e5112 1package api
2
3import "net/http"
4
5//go:generate stringer -type=Status,ErrorCode -output const_string.go
6type Status uint32
7type ErrorCode uint32
8
24e47979 9const EXTERNAL_SERVICE_TIMEOUT_SECONDS = 20
2f91f20a 10
7a9e5112 11const (
12 OK Status = iota
13 NOK
14
15 BadRequest ErrorCode = iota + 1
16 EmailExists
2f91f20a 17 ExternalServiceTimeout
7a9e5112 18 InternalError
19 InvalidCredentials
20 InvalidEmail
2f91f20a 21 InvalidMarketCredentials
c6aa553f 22 MarketCredentialsNotConfigured
908ee2dd 23 IPRestrictedApiKey
7a9e5112 24 InvalidOtp
25 InvalidPassword
26 NeedOtpValidation
27 NotAuthorized
28 NotFound
29 OtpAlreadySetup
30 OtpNotSetup
31 UserNotConfirmed
32)
33
34func StatusToHttpCode(status Status, code ErrorCode) int {
35 if status == OK {
36 return http.StatusOK
37 }
38
39 switch code {
c6aa553f 40 case BadRequest, InvalidPassword, InvalidEmail, InvalidMarketCredentials, IPRestrictedApiKey, MarketCredentialsNotConfigured:
7a9e5112 41 return http.StatusBadRequest
42
43 case InvalidCredentials, InvalidOtp:
44 return http.StatusUnauthorized
45
46 case UserNotConfirmed, NotAuthorized, OtpAlreadySetup, OtpNotSetup, NeedOtpValidation:
47 return http.StatusForbidden
48
49 case EmailExists:
50 return http.StatusConflict
51
52 case NotFound:
53 return http.StatusNotFound
2f91f20a 54
55 case ExternalServiceTimeout:
56 return http.StatusGatewayTimeout
7a9e5112 57 }
58
59 return http.StatusInternalServerError
60}