Skip to content

Commit

Permalink
fix: API error Unmarshaling (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet authored Jul 13, 2023
1 parent 16dd3b0 commit ef13e9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 4 additions & 7 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ const (
var ErrorTypeAssert = Error{
Err: errors.New("type assertion failed"),
HTTPStatusCode: http.StatusUnprocessableEntity,
Msg: "type assertion failed",
}

type ErrorDetail struct {
ErrorCode []ErrorCode `json:"code,omitempty"`
Message: "Type assertion failed",
}

type Error struct {
Err error `json:"-"`

HTTPStatusCode int `json:"status"`
Msg string `json:"message"`
Message string `json:"error"`
ErrorCode string `json:"code"`

ErrorDetail ErrorDetail `json:"error_details"`
ErrorDetail map[string][]string `json:"error_details,omitempty"`
}

func (e ErrorCode) Error() string {
Expand Down
14 changes: 7 additions & 7 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (wr *WebhookRequest) GetPublicKey(ctx context.Context) (*rsa.PublicKey, *Er
return nil, &Error{
Err: errors.New("response is not a string"),
HTTPStatusCode: http.StatusInternalServerError,
Msg: "response is not a string",
Message: "response is not a string",
}
}

Expand All @@ -48,7 +48,7 @@ func (wr *WebhookRequest) GetPublicKey(ctx context.Context) (*rsa.PublicKey, *Er
return nil, &Error{
Err: decodeErr,
HTTPStatusCode: http.StatusInternalServerError,
Msg: "cannot decode the key",
Message: "cannot decode the key",
}
}

Expand All @@ -58,7 +58,7 @@ func (wr *WebhookRequest) GetPublicKey(ctx context.Context) (*rsa.PublicKey, *Er
return nil, &Error{
Err: errors.New("Failed to decode PEM block containing public key"),
HTTPStatusCode: http.StatusInternalServerError,
Msg: "Failed to decode PEM block containing public key",
Message: "Failed to decode PEM block containing public key",
}
}

Expand All @@ -68,7 +68,7 @@ func (wr *WebhookRequest) GetPublicKey(ctx context.Context) (*rsa.PublicKey, *Er
return nil, &Error{
Err: parseErr,
HTTPStatusCode: http.StatusInternalServerError,
Msg: "Failed to to parse the public key",
Message: "Failed to to parse the public key",
}
}

Expand All @@ -77,7 +77,7 @@ func (wr *WebhookRequest) GetPublicKey(ctx context.Context) (*rsa.PublicKey, *Er
return nil, &Error{
Err: errors.New("Unexpected type of public key"),
HTTPStatusCode: http.StatusInternalServerError,
Msg: "Unexpected type of public key",
Message: "Unexpected type of public key",
}
}

Expand All @@ -100,7 +100,7 @@ func (wr *WebhookRequest) parseSignature(ctx context.Context, signature string)
return nil, &Error{
Err: parseErr,
HTTPStatusCode: http.StatusInternalServerError,
Msg: "cannot parse token",
Message: "cannot parse token",
}
}

Expand All @@ -122,7 +122,7 @@ func (wr *WebhookRequest) ValidateBody(ctx context.Context, signature string, bo
return false, &Error{
Err: errors.New("error casting claims"),
HTTPStatusCode: http.StatusInternalServerError,
Msg: "cannot parse token",
Message: "cannot parse token",
}
}

Expand Down

0 comments on commit ef13e9b

Please sign in to comment.