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

downgrade to go 1.19 (node dependency) #14

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 24 additions & 9 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"net/url"
"os"
"path"
"strings"
"time"

"github.com/mysteriumnetwork/feedback/feedback"
"github.com/mysteriumnetwork/feedback/infra/apierror"
apierr "github.com/mysteriumnetwork/go-rest/apierror"
)

const basePath = "/api/v1"
Expand Down Expand Up @@ -47,7 +49,7 @@ func (f *FeedbackAPI) apiURL(apiPath string) string {
}

// CreateGithubIssue creates a github issue
func (f *FeedbackAPI) CreateGithubIssue(request feedback.CreateGithubIssueRequest, logFilePath string) (*feedback.CreateGithubIssueResponse, *apierror.APIErrorResponse, error) {
func (f *FeedbackAPI) CreateGithubIssue(request feedback.CreateGithubIssueRequest, logFilePath string) (*feedback.CreateGithubIssueResponse, *apierr.APIError, error) {
multipartReq := newMultipartRequest()
err := multipartReq.addFileToMultipart("file", logFilePath)
if err != nil {
Expand Down Expand Up @@ -83,7 +85,7 @@ func (f *FeedbackAPI) CreateGithubIssue(request feedback.CreateGithubIssueReques
}

// CreateIntercomIssue creates a intercom issue
func (f *FeedbackAPI) CreateIntercomIssue(request feedback.CreateIntercomIssueRequest, logFilePath string) (*feedback.CreateIntercomIssueResponse, *apierror.APIErrorResponse, error) {
func (f *FeedbackAPI) CreateIntercomIssue(request feedback.CreateIntercomIssueRequest, logFilePath string) (*feedback.CreateIntercomIssueResponse, *apierr.APIError, error) {
multipartReq := newMultipartRequest()
err := multipartReq.addFileToMultipart("file", logFilePath)
if err != nil {
Expand Down Expand Up @@ -119,7 +121,7 @@ func (f *FeedbackAPI) CreateIntercomIssue(request feedback.CreateIntercomIssueRe
}

// CreateBugReport creates a bug report
func (f *FeedbackAPI) CreateBugReport(request feedback.CreateBugReportRequest, logFilePath string) (*feedback.CreateBugReportResponse, *apierror.APIErrorResponse, error) {
func (f *FeedbackAPI) CreateBugReport(request feedback.CreateBugReportRequest, logFilePath string) (*feedback.CreateBugReportResponse, *apierr.APIError, error) {
multipartReq := newMultipartRequest()
err := multipartReq.addFileToMultipart("file", logFilePath)
if err != nil {
Expand Down Expand Up @@ -263,18 +265,31 @@ func (mr *multipartRequest) finalize() (*bytes.Buffer, string, error) {
return mr.buffer, mr.writer.FormDataContentType(), nil
}

func parseResponse(resp *http.Response, v any) (*apierror.APIErrorResponse, error) {
func parseResponse(resp *http.Response, v any) (*apierr.APIError, error) {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could read response: %w", err)
}
if resp.StatusCode >= 400 {
apierror := apierror.APIErrorResponse{}
err = json.Unmarshal(body, &apierror)
if err != nil {
return nil, fmt.Errorf("could not parse error response: %w", err)

switch resp.StatusCode {
case http.StatusBadRequest:
apierror := apierror.APIErrorResponse{}
err = json.Unmarshal(body, &apierror)
if err != nil {
return nil, fmt.Errorf("could not parse error response: %w", err)
}
errors := make([]string, len(apierror.Errors))
for i, err := range apierror.Errors {
errors[i] = err.Message
}
return apierr.BadRequest(strings.Join(errors, ", "), "bad_request"), nil
case http.StatusTooManyRequests:
return apierr.Error(http.StatusTooManyRequests, "too many requests", "too_many_requests"), nil
case http.StatusServiceUnavailable:
return apierr.Error(http.StatusServiceUnavailable, "service unavailable", "service_unavailable"), nil
}
return &apierror, nil
return apierr.InternalDefault(), nil
}
err = json.Unmarshal(body, v)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestApi(t *testing.T) {
if test.fails {
assert.NotNil(t, apierr)
assert.Nil(t, err)
assert.Contains(t, apierr.Errors[0].Message, test.errorContains)
assert.Contains(t, apierr.Message(), test.errorContains)
} else {
assert.NotNil(t, resp)
assert.Nil(t, apierr)
Expand Down
2 changes: 1 addition & 1 deletion e2e/intercom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestIntercomReporting(t *testing.T) {
_, apiErr, err := apiClient.CreateIntercomIssue(*req, f.Name())
assert.Nil(t, err)
assert.NotNil(t, apiErr)
assert.Contains(t, apiErr.Errors[0].Message, "could not create intercom conversation")
assert.Contains(t, apiErr.Message(), "service unavailable")
})

t.Run("report an issue on intercom with email", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions feedback/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func ParseIntercomIssueRequest(c *gin.Context) (CreateIntercomIssueRequest, []er
// @Success 200 {object} feedback.CreateIntercomIssueResponse
// @Failure 400 {object} apierror.APIErrorResponse
// @Failure 429
// @Failure 500 {object} apierror.APIErrorResponse
// @Failure 503 {object} apierror.APIErrorResponse
// @Router /v1/intercom [post]
// @Deprecated
func (e *Endpoint) CreateIntercomIssue(c *gin.Context) {
Expand Down Expand Up @@ -313,7 +313,7 @@ type CreateBugReportResponse struct {
// @Success 200 {object} feedback.CreateBugReportResponse
// @Failure 400 {object} apierror.APIErrorResponse
// @Failure 429
// @Failure 500 {object} apierror.APIErrorResponse
// @Failure 503 {object} apierror.APIErrorResponse
// @Router /v1/bug-report [post]
func (e *Endpoint) CreateBugReport(c *gin.Context) {
form, requestErrs := ParseBugReportRequest(c)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/mysteriumnetwork/feedback

go 1.21
go 1.19

require (
github.com/aws/aws-sdk-go-v2 v1.21.2
github.com/aws/aws-sdk-go-v2/config v1.19.0
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.91
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2
github.com/didip/tollbooth/v5 v5.2.0
github.com/ethereum/go-ethereum v1.13.3
github.com/ethereum/go-ethereum v1.10.17
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/go-bindata/go-bindata v3.1.2+incompatible
Expand All @@ -20,6 +20,7 @@ require (
github.com/magefile/mage v1.15.0
github.com/mailru/easyjson v0.7.7
github.com/mysteriumnetwork/go-ci v0.0.0-20220711082519-1245471bae0d
github.com/mysteriumnetwork/go-rest v0.3.1
github.com/mysteriumnetwork/logger v0.0.9
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
Expand Down
Loading