Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ade96de

Browse files
committed
update internal error message
1 parent 52c23fb commit ade96de

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

coderd/httpmw/apikey.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ type OAuth2Configs struct {
5151
Github OAuth2Config
5252
}
5353

54-
const signedOutErrorMessage string = "You are signed out or your session has expired. Please sign in again to continue."
54+
const (
55+
signedOutErrorMessage string = "You are signed out or your session has expired. Please sign in again to continue."
56+
internalErrorMessage string = "An internal error occurred. Please try again or contact the system administrator."
57+
)
5558

5659
// ExtractAPIKey requires authentication using a valid API key.
5760
// It handles extending an API key if it comes close to expiry,
@@ -126,8 +129,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs, redirectToLogin bool
126129
return
127130
}
128131
write(http.StatusInternalServerError, codersdk.Response{
129-
Message: "Internal error fetching API key by id.",
130-
Detail: err.Error(),
132+
Message: internalErrorMessage,
133+
Detail: fmt.Sprintf("Internal error fetching API key by id. %s", err.Error()),
131134
})
132135
return
133136
}
@@ -154,7 +157,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs, redirectToLogin bool
154157
oauthConfig = oauth.Github
155158
default:
156159
write(http.StatusInternalServerError, codersdk.Response{
157-
Message: fmt.Sprintf("Unexpected authentication type %q.", key.LoginType),
160+
Message: internalErrorMessage,
161+
Detail: fmt.Sprintf("Unexpected authentication type %q.", key.LoginType),
158162
})
159163
return
160164
}
@@ -225,7 +229,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs, redirectToLogin bool
225229
})
226230
if err != nil {
227231
write(http.StatusInternalServerError, codersdk.Response{
228-
Message: signedOutErrorMessage,
232+
Message: internalErrorMessage,
229233
Detail: fmt.Sprintf("API key couldn't update: %s.", err.Error()),
230234
})
231235
return
@@ -238,8 +242,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs, redirectToLogin bool
238242
roles, err := db.GetAuthorizationUserRoles(r.Context(), key.UserID)
239243
if err != nil {
240244
write(http.StatusUnauthorized, codersdk.Response{
241-
Message: "Internal error fetching user's roles.",
242-
Detail: err.Error(),
245+
Message: internalErrorMessage,
246+
Detail: fmt.Sprintf("Internal error fetching user's roles. %s", err.Error()),
243247
})
244248
return
245249
}

0 commit comments

Comments
 (0)