@@ -31,6 +31,7 @@ var LinkRoute = MakeRouteSpec[LinkRequest, LinkResponse](
3131
3232var (
3333 ErrActionMissing = errors .New ("Action missing in request" )
34+ ErrActionDNE = errors .New ("Specified action does not exist" )
3435 ErrDiscordIDMissing = errors .New ("Discord ID missing or invalid" )
3536 ErrDiscordLinked = errors .New ("Discord ID already linked to another profile" )
3637 ErrDiscordWrongStep = errors .New ("Profile is not in the correct step to link Discord ID" )
@@ -57,7 +58,7 @@ func HandleLink(req any, _ bool, _ *http.Request) (any, int, error) {
5758 return res , http .StatusBadRequest , ErrDiscordIDMissing
5859 }
5960
60- if _req .Action == "" || ( _req . Action != "link" && _req . Action != "check" && _req . Action != "unlink" ) {
61+ if _req .Action == "" {
6162 return res , http .StatusBadRequest , ErrActionMissing
6263 }
6364
@@ -67,7 +68,8 @@ func HandleLink(req any, _ bool, _ *http.Request) (any, int, error) {
6768 return res , http .StatusInternalServerError , gpcm .ErrNoSession
6869 }
6970
70- if _req .Action == "link" {
71+ switch _req .Action {
72+ case "link" :
7173 // This is kind of just stuck in here, bits of duplicate code. Should
7274 // be cleaned up eventually.
7375 if _req .Force {
@@ -110,7 +112,7 @@ func HandleLink(req any, _ bool, _ *http.Request) (any, int, error) {
110112 if gpcm .SetSessionDiscordInfo (_req .ProfileID , database .LS_STARTED , _req .DiscordID ) != nil {
111113 return res , http .StatusInternalServerError , gpcm .ErrNoSession
112114 }
113- } else if _req . Action == "check" {
115+ case "check" :
114116 // Once the user friends the correct code, the stage progresses from
115117 // LS_STARTED to LS_FRIENDED. See gpcm/friend::handleFriendBot
116118 if linkStage != database .LS_FRIENDED {
@@ -130,7 +132,7 @@ func HandleLink(req any, _ bool, _ *http.Request) (any, int, error) {
130132 if user .UpdateDiscordID (pool , ctx , _req .DiscordID ) != nil {
131133 return res , http .StatusInternalServerError , ErrTransaction
132134 }
133- } else if _req . Action == "reset" {
135+ case "reset" :
134136 // Only requirement to reset is that the profile has begun linking, and your ID matches
135137 // Since the ID is applied to the gpcm session on first link, it
136138 // prevents griefing (if a reset command is ever added), but squatting
@@ -149,6 +151,8 @@ func HandleLink(req any, _ bool, _ *http.Request) (any, int, error) {
149151 if user .UpdateDiscordID (pool , ctx , "" ) != nil {
150152 return res , http .StatusInternalServerError , ErrTransaction
151153 }
154+ default :
155+ return res , http .StatusBadRequest , ErrActionDNE
152156 }
153157
154158 return res , http .StatusOK , nil
0 commit comments