Skip to content

Invalid error description for 4xx status code without body #67

@gerardva

Description

@gerardva

Description of the Bug

When doing a request which results in a 4xx status code without a body, an error with the following description is returned:

Sorry, something went wrong when trying to process the request. If this problem persists, contact us at support@chargebee.com. type: internal_error, http_status_code: 500, error_code: internal_error, content:

This incorrectly states that the status code was 500. This seems to be caused by this code:

return fmt.Errorf("Sorry, something went wrong when trying to process the request. If this problem persists, contact us at support@chargebee.com. \n type: internal_error, \n http_status_code: 500, \n error_code: internal_error,\n content: %q", bodyStr)
, where an error occurs when trying to Unmarshal the empty body content to an Error struct which makes it fall back to this default error.

I experienced this for the EntitlementsForCustomer request.

Steps to reproduce

  1. Make a EntitlementsForCustomer request with an invalid customer ID (for example a url as that contains characters that are not allowed): res, err := customerentitlement.EntitlementsForCustomer(invalidCustomerID, params).ListRequest()
  2. Check the error in the err variable

Expected Behavior

I would expect an error which correctly states the status code

Code Snippets (if applicable)

Operating System

macOS

Language version

1.25.0

Library version

v3.38.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions