-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a custom error for the api client. Update error messages in the commands.
- Loading branch information
Showing
3 changed files
with
43 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
) | ||
|
||
// QaseApiError is an error returned by Qase API | ||
type QaseApiError struct { | ||
message string | ||
reason string | ||
} | ||
|
||
// NewQaseApiError creates a new QaseApiError | ||
func NewQaseApiError(message string, reason io.ReadCloser) *QaseApiError { | ||
bodyBytes, err := io.ReadAll(reason) | ||
if err != nil { | ||
log.Fatalf("Failed to read body: %v", err) | ||
} | ||
|
||
return &QaseApiError{ | ||
message: message, | ||
reason: string(bodyBytes), | ||
} | ||
} | ||
|
||
// Error returns a string representation of the error | ||
func (e *QaseApiError) Error() string { | ||
return fmt.Sprintf("Message: %s. Reason: %s.", e.message, e.reason) | ||
} |