Skip to content

Commit

Permalink
fix: replacing HTML content body with plain text error on 503 (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
DazWilkin and ldez authored Aug 22, 2023
1 parent b6c205c commit 926336f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,21 @@ func (c *Client) do(ctx context.Context, endpoint *url.URL, apiRequest interface
return nil, fmt.Errorf("failed to read response body: %w", err)
}

if resp.StatusCode != http.StatusOK {
switch resp.StatusCode {
case http.StatusOK:
return respBody, nil

case http.StatusServiceUnavailable:
// related to https://github.com/nrdcg/porkbun/issues/5
return nil, &ServerError{
StatusCode: resp.StatusCode,
Message: http.StatusText(http.StatusServiceUnavailable),
}

default:
return nil, &ServerError{
StatusCode: resp.StatusCode,
Message: string(respBody),
}
}

return respBody, nil
}

0 comments on commit 926336f

Please sign in to comment.