-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error handling for TooManyRequests API responses
[#147953573] Signed-off-by: Saman Alvi <[email protected]>
- Loading branch information
1 parent
ae97481
commit fc8a1ab
Showing
5 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,7 +219,12 @@ func (p ProductFilesService) Create(config CreateProductFileConfig) (ProductFile | |
bytes.NewReader(b), | ||
) | ||
if err != nil { | ||
return ProductFile{}, err | ||
_, ok := err.(ErrTooManyRequests) | ||
if ok { | ||
return ProductFile{}, fmt.Errorf("You have hit the file creation limit. Please wait before creating more files. Contact [email protected] with additional questions.") | ||
} else { | ||
return ProductFile{}, err | ||
} | ||
} | ||
defer resp.Body.Close() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -527,6 +527,24 @@ var _ = Describe("PivnetClient - product files", func() { | |
}) | ||
}) | ||
|
||
Context("when the server responds with a 429 status code", func() { | ||
It("returns an error indicating the limit was hit", func() { | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest("POST", fmt.Sprintf( | ||
"%s/products/%s/product_files", | ||
apiPrefix, | ||
productSlug, | ||
)), | ||
ghttp.RespondWith(http.StatusTooManyRequests, "Retry later"), | ||
), | ||
) | ||
|
||
_, err := client.ProductFiles.Create(createProductFileConfig) | ||
Expect(err.Error()).To(ContainSubstring("You have hit the file creation limit. Please wait before creating more files. Contact [email protected] with additional questions.")) | ||
}) | ||
}) | ||
|
||
Context("when the json unmarshalling fails with error", func() { | ||
It("forwards the error", func() { | ||
server.AppendHandlers( | ||
|