Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up HandleAccessTokenRequest #19

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Clean up HandleAccessTokenRequest
- check for error first and for result second
- if neither error nor result is present, that is an Internal Server Error
- code worked fine before, but a change in `AccessTokenProcedure` in the future
  could have messed it up.
GKnirps committed Jul 4, 2023
commit 297e1a28564d163c58faa95067adecf8eef97cda
12 changes: 7 additions & 5 deletions internal/sbi/producer/access_token.go
Original file line number Diff line number Diff line change
@@ -27,17 +27,19 @@ func HandleAccessTokenRequest(request *httpwrapper.Request) *httpwrapper.Respons

response, errResponse := AccessTokenProcedure(accessTokenReq)

if response != nil {
if errResponse != nil {
return httpwrapper.NewResponse(http.StatusBadRequest, nil, errResponse)
} else if response != nil {
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if errResponse != nil {
return httpwrapper.NewResponse(http.StatusBadRequest, nil, errResponse)
}

logger.AccTokenLog.Errorln("AccessTokenProcedure returned neither an error nor a response")
problemDetails := &models.ProblemDetails{
Status: http.StatusForbidden,
Status: http.StatusInternalServerError,
Cause: "UNSPECIFIED",
}
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
return httpwrapper.NewResponse(http.StatusInternalServerError, nil, problemDetails)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please modify to:
httpwrapper.NewResponse(problemDetails.Status, nil, problemDetails)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently on vacation, I'll do it when I get back (next week).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

func AccessTokenProcedure(request models.AccessTokenReq) (