-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from celestiaorg/mojtaba/sdk-error-enhancement
feat: add a more precise error handling to the SDK
- Loading branch information
Showing
9 changed files
with
120 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,5 @@ | |
# Go workspace file | ||
go.work | ||
bin/ | ||
*.o | ||
run.sh | ||
.vscode/ |
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,65 @@ | ||
package sdk | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/celestiaorg/bittwister/api/v1" | ||
) | ||
|
||
type Error struct { | ||
Message MetaMessage | ||
} | ||
|
||
// Error returns the error message as a string | ||
func (e Error) Error() string { | ||
errJSON, _ := json.MarshalIndent(e.Message, "", " ") | ||
return string(errJSON) | ||
} | ||
|
||
func IsErrorServiceNotInitialized(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceNotInitialized | ||
} | ||
|
||
func IsErrorServiceAlreadyStarted(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceAlreadyStarted | ||
} | ||
|
||
func IsErrorServiceNotStarted(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceNotStarted | ||
} | ||
|
||
func IsErrorServiceStopFailed(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceStopFailed | ||
} | ||
|
||
func IsErrorServiceStartFailed(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceStartFailed | ||
} | ||
|
||
func IsErrorServiceNotReady(err error) bool { | ||
e, ok := err.(Error) | ||
if !ok { | ||
return false | ||
} | ||
return e.Message.Slug == api.SlugServiceNotReady | ||
} |
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
Binary file not shown.
Binary file not shown.