Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Created a custom HTTP error package #6

Merged
merged 2 commits into from
Jan 29, 2019
Merged

Created a custom HTTP error package #6

merged 2 commits into from
Jan 29, 2019

Conversation

craicoverflow
Copy link

Created custom package to return HTTP errors in a concise manner

Motivation

JIRA: https://issues.jboss.org/browse/AEROGEAR-839

What

Created a custom package to wrap Echo's HTTP error handler and return HTTP errors with a JSON body.

Why

The default HTTP error handling that comes with Echo is a bit verbose and could do with improvements.

Example:

return echo.NewHTTPError(http.StatusUnauthorized, "Please provide valid credentials")

This could be improved to be like this:

return httperrors.Unauthorized(c, "Please provide valid credentials")

How

  1. Created a custom package in pkg/httperrors/httperrors.go.
  2. Created functions for the common HTTP status codes (e.g. 404 Not Found)

Verification Steps

Add the steps required to check this change. Following an example.

  1. Go to cmd/mobile-security-service-server/main.go
  2. Import the httperrors package:
import (
	"github.com/aerogear/mobile-security-service-server/pkg/httperrors"
        ...
)
  1. Add the following code block in main() after e := echo.New():
e.GET("/test", func(c echo.Context) error {
        return httperrors.NotFound(c, "Test")
})
  1. Run go run cmd/mobile-security-service-server/main.go to start the server.

  2. Go to http://localhost:3000/test (replace with your own port). You should see a response body like this:

{
    "message": "Test",
    "statusCode": 404
}
  1. You can repeat this with the other status codes.

Checklist:

  • Code has been tested locally by PR requester
  • Changes have been successfully verified by another team member

Progress

  • Finished task
  • TODO

Copy link
Member

@davidffrench davidffrench left a comment

Choose a reason for hiding this comment

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

Looks great, code changes look good to me.

Created custom package to return HTTP errors in a concise manner
Copy link
Member

@davidffrench davidffrench left a comment

Choose a reason for hiding this comment

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

verified changes work as expected. Great work Enda

@craicoverflow craicoverflow merged commit ecb03c5 into aerogear:master Jan 29, 2019
@craicoverflow craicoverflow deleted the AEROGEAR-8390 branch January 29, 2019 11:06
jhellar pushed a commit to jhellar/mobile-security-service that referenced this pull request Nov 13, 2019
feat(add configmap) : Add config map to save required data info for the SDK
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants