-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
238 additions
and
279 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package teedy | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
type TeedyAPIError struct { | ||
GetAll error | ||
Get error | ||
Add error | ||
Delete error | ||
Update error | ||
} | ||
|
||
func NewTeedyAPIError(api string) *TeedyAPIError { | ||
return &TeedyAPIError{ | ||
GetAll: fmt.Errorf("error getting all %ss", api), | ||
Get: fmt.Errorf("error getting %s", api), | ||
Add: fmt.Errorf("error adding %s", api), | ||
Delete: fmt.Errorf("error deleting %s", api), | ||
Update: fmt.Errorf("error updating %s", api), | ||
} | ||
} | ||
|
||
func (n *TeedyAPIError) Custom(description string) error { | ||
return fmt.Errorf("error %s", description) | ||
} | ||
|
||
func checkRequestError(resp *resty.Response, respError, errorDescription error) error { | ||
if respError != nil { | ||
return fmt.Errorf("%s: %w", errorDescription, respError) | ||
} | ||
|
||
if resp.StatusCode() != http.StatusOK { | ||
return fmt.Errorf("%s: invalid response code: %s", errorDescription, resp.Status()) | ||
} | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.