Skip to content

Commit

Permalink
chore: Clean up linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdavis3 committed Jul 25, 2024
1 parent 8c548bb commit 4adfc20
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
24 changes: 12 additions & 12 deletions problems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
// Basic example
func Example() {
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
_ = prob.Set("Title", "Test Error")
_ = prob.Set("Instance", "/error/test")
prob.PrettyPrint()
// Output: {
// "detail": "An Error has occurred",
Expand All @@ -27,10 +27,10 @@ func Example() {
// extended attributes
func Example_extended() {
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
prob.Set("Type", "uri:example:extended")
prob.Set("TraceID", "12345-67890")
_ = prob.Set("Title", "Test Error")
_ = prob.Set("Instance", "/error/test")
_ = prob.Set("Type", "uri:example:extended")
_ = prob.Set("TraceID", "12345-67890")
prob.PrettyPrint()
// Output: {
// "detail": "An Error has occurred",
Expand All @@ -48,14 +48,14 @@ func Example_extended() {
// extended attributes
func Example_array() {
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
prob.Set("Type", "uri:example:extended")
prob.Set("TraceID", "12345-67890")
_ = prob.Set("Title", "Test Error")
_ = prob.Set("Instance", "/error/test")
_ = prob.Set("Type", "uri:example:extended")
_ = prob.Set("TraceID", "12345-67890")
issues := make(map[string]interface{})
issues["field"] = "state"
issues["message"] = "A valid state must be provided"
prob.Set("invalid-params", []map[string]interface{}{issues})
_ = prob.Set("invalid-params", []map[string]interface{}{issues})
prob.PrettyPrint()
// Output: {
// "detail": "An Error has occurred",
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestProblem_Render(t *testing.T) {
Attributes: tt.fields.Attributes,
err: tt.fields.err,
}
prob.Render(tt.args.w, tt.args.r)
_ = prob.Render(tt.args.w, tt.args.r)
})
}
}
Expand Down
64 changes: 32 additions & 32 deletions standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,50 @@ func init() {
func GetNoAccessResponse() *Problem {
prob := New(401, "No Bearer access token found in Authorization HTTP header")
prob.Type = TypeNoAccessToken
prob.Set("Title", "No Access Token")
_ = prob.Set("Title", "No Access Token")
return prob
}

func GetInvalidTokenResponse() *Problem {
prob := New(401, "The Bearer access token found in the Authorization HTTP header is invalid")
prob.Set("Title", "Invalid Access Token")
prob.Set("Type", TypeInvalidToken)
_ = prob.Set("Title", "Invalid Access Token")
_ = prob.Set("Type", TypeInvalidToken)
return prob
}

func GetExpiredTokenResponse() *Problem {
prob := New(401, "The Bearer access token found in the Authorization HTTP header has expired")
prob.Set("Type", TypeTokenExpired)
prob.Set("Title", "Expired Access Token")
_ = prob.Set("Type", TypeTokenExpired)
_ = prob.Set("Title", "Expired Access Token")
return prob
}

func GetMissingScopeResponse(scopes []string) *Problem {
prob := New(403, "Forbidden to consult the resource")
prob.Set("Type", TypeMissingScope)
prob.Set("Title", "Missing Scope")
_ = prob.Set("Type", TypeMissingScope)
_ = prob.Set("Title", "Missing Scope")

prob.Set("requiredScopes", scopes)
_ = prob.Set("requiredScopes", scopes)
return prob
}

func GetMissingPermission() *Problem {
prob := New(403, "Not permitted to update the details of this resource")
prob.Set("Type", TypeMissingPermission)
prob.Set("Title", "Missing Permission")
_ = prob.Set("Type", TypeMissingPermission)
_ = prob.Set("Title", "Missing Permission")
return prob
}

func GetInternalErrorResponse(detail string) *Problem {
prob := New(http.StatusInternalServerError, detail)
prob.Set("Type", TypeInternalServerError)
prob.Set("Title", http.StatusText(http.StatusInternalServerError))
_ = prob.Set("Type", TypeInternalServerError)
_ = prob.Set("Title", http.StatusText(http.StatusInternalServerError))
return prob
}

func GetErrorResponseFromError(err error) *Problem {
prob := FromError(err)
prob.Set("Type", TypeInternalServerError)
_ = prob.Set("Type", TypeInternalServerError)
return prob
}

Expand All @@ -103,19 +103,19 @@ type MissingResourceParam struct {
// GetMissingResource creates a Problem that defines the resource that was not found
func GetMissingResource(resource MissingResourceParam) *Problem {
prob := New(404, "Missing Resource")
prob.Set("Type", TypeNotFound)
prob.Set("Title", "Resource not found")
prob.Set("Detail", fmt.Sprintf("No resource %s:%s found", resource.ResourceType, resource.ResourceValue))
_ = prob.Set("Type", TypeNotFound)
_ = prob.Set("Title", "Resource not found")
_ = prob.Set("Detail", fmt.Sprintf("No resource %s:%s found", resource.ResourceType, resource.ResourceValue))

issue := Problem{}
issue.Set("Type", TypeNotFound)
_ = issue.Set("Type", TypeNotFound)
if resource.Location != "" {
issue.Set("in", resource.Location)
_ = issue.Set("in", resource.Location)
}
issue.Set("name", resource.ResourceType)
issue.Set("detail", fmt.Sprintf("the %s %v is not assigned", resource.ResourceType, resource.ResourceValue))
issue.Set("value", resource.ResourceValue)
prob.Set("issues", []interface{}{issue})
_ = issue.Set("name", resource.ResourceType)
_ = issue.Set("detail", fmt.Sprintf("the %s %v is not assigned", resource.ResourceType, resource.ResourceValue))
_ = issue.Set("value", resource.ResourceValue)
_ = prob.Set("issues", []interface{}{issue})
return prob
}

Expand All @@ -129,30 +129,30 @@ type ValidationParam struct {

func GetInputValidationResponse(validations ...ValidationParam) *Problem {
prob := New(400, "The input message is incorrect; see issues for more information")
prob.Set("Type", TypeBadRequest)
prob.Set("Title", "Bad Request")
_ = prob.Set("Type", TypeBadRequest)
_ = prob.Set("Title", "Bad Request")

if len(validations) == 1 {
prob.Set("Detail", validations[0].Issue)
_ = prob.Set("Detail", validations[0].Issue)
}

issues := make([]Problem, 0)

for _, validation := range validations {
issue := Problem{}
if validation.IsUnknown {
issue.Set("Type", TypeUnknownParameter)
_ = issue.Set("Type", TypeUnknownParameter)
} else {
issue.Set("Type", TypeSchemaViolation)
_ = issue.Set("Type", TypeSchemaViolation)
}
issue.Set("in", validation.Location)
issue.Set("name", validation.Name)
issue.Set("value", validation.Value)
issue.Set("Detail", validation.Issue)
_ = issue.Set("in", validation.Location)
_ = issue.Set("name", validation.Name)
_ = issue.Set("value", validation.Value)
_ = issue.Set("Detail", validation.Issue)
issues = append(issues, issue)
}

prob.Set("issues", issues)
_ = prob.Set("issues", issues)
return prob
}

Expand Down

0 comments on commit 4adfc20

Please sign in to comment.