Skip to content

Commit

Permalink
Explicitly handle error 404 the API can return.
Browse files Browse the repository at this point in the history
I'd forgotten about this case, but it's used when the user hasn't set
any Image Optimizer settings, and it's useful for terraform to be able
to easily detect this case.

I assume other users of this API will also appreciate this explicit
error handling, as opposed to having to check for error 404 themselves.
  • Loading branch information
daboross committed Apr 19, 2024
1 parent 98d89ed commit 0206fb9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fastly/image_optimizer_default_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type UpdateImageOptimizerDefaultSettingsInput struct {
}

// GetImageOptimizerDefaultSettings retrives the current Image Optimizer default settings on a given service version.
//
// Returns (nil, nil) if no default settings are set.
func (c *Client) GetImageOptimizerDefaultSettings(i *GetImageOptimizerDefaultSettingsInput) (*ImageOptimizerDefaultSettings, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
Expand All @@ -99,6 +101,12 @@ func (c *Client) GetImageOptimizerDefaultSettings(i *GetImageOptimizerDefaultSet

resp, err := c.Get(path, nil)
if err != nil {
if herr, ok := err.(*HTTPError); ok {
if herr.StatusCode == 404 {
// API endpoint returns 404 for services without Image Optimizer settings set.
return nil, nil
}
}
return nil, err
}
defer resp.Body.Close()
Expand Down

0 comments on commit 0206fb9

Please sign in to comment.