- Notifications
You must be signed in to change notification settings - Fork928
Add helper text to unauthorized error messages#1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
4acc66e
add helper text to unauthorized error messages
AbhineetJain1f60701
fix lint error, add unit tests
AbhineetJain66b30a8
fix test name
AbhineetJain499168c
fix test name
AbhineetJain0fcebc4
fix lint errors in test
AbhineetJainf6c7199
add unauthorized test for templates create
AbhineetJainc44879d
remove unnecessary variable
AbhineetJain131bb8e
Merge main into 917-bug-cleaner-error-message
AbhineetJain00fd392
remove Error struct, change error message
AbhineetJain60771ae
change [url] to <url>
AbhineetJainFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletionscli/root.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
53 changes: 39 additions & 14 deletionscli/userlist_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletionscoderd/templates_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletionscodersdk/client.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -125,6 +125,14 @@ func (c *Client) dialWebsocket(ctx context.Context, path string) (*websocket.Con | ||
// wraps it in a codersdk.Error type for easy marshaling. | ||
funcreadBodyAsError(res*http.Response)error { | ||
contentType:=res.Header.Get("Content-Type") | ||
varhelperstring | ||
ifres.StatusCode==http.StatusUnauthorized { | ||
// 401 means the user is not logged in | ||
// 403 would mean that the user is not authorized | ||
helper="Try logging in using 'coder login <url>'." | ||
} | ||
AbhineetJain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
ifstrings.HasPrefix(contentType,"text/plain") { | ||
resp,err:=io.ReadAll(res.Body) | ||
iferr!=nil { | ||
@@ -135,6 +143,7 @@ func readBodyAsError(res *http.Response) error { | ||
Response: httpapi.Response{ | ||
Message:string(resp), | ||
}, | ||
Helper:helper, | ||
} | ||
} | ||
@@ -146,13 +155,15 @@ func readBodyAsError(res *http.Response) error { | ||
// If no body is sent, we'll just provide the status code. | ||
return&Error{ | ||
statusCode:res.StatusCode, | ||
Helper:helper, | ||
} | ||
} | ||
returnxerrors.Errorf("decode body: %w",err) | ||
} | ||
return&Error{ | ||
Response:m, | ||
statusCode:res.StatusCode, | ||
Helper:helper, | ||
} | ||
} | ||
@@ -162,6 +173,8 @@ type Error struct { | ||
httpapi.Response | ||
statusCodeint | ||
Helperstring | ||
} | ||
func (e*Error)StatusCode()int { | ||
@@ -171,6 +184,9 @@ func (e *Error) StatusCode() int { | ||
func (e*Error)Error()string { | ||
varbuilder strings.Builder | ||
_,_=fmt.Fprintf(&builder,"status code %d: %s",e.statusCode,e.Message) | ||
ife.Helper!="" { | ||
_,_=fmt.Fprintf(&builder,": %s",e.Helper) | ||
} | ||
for_,err:=rangee.Errors { | ||
_,_=fmt.Fprintf(&builder,"\n\t%s: %s",err.Field,err.Detail) | ||
} | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.