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