-
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 #6 from nvima/refactor-error-handling-status-code
Refactor CLI tool: Improved error handling, added status code check
- Loading branch information
Showing
5 changed files
with
137 additions
and
41 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,63 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type TplError struct { | ||
msg string | ||
err error | ||
exitCode int | ||
} | ||
|
||
func (te TplError) Err() error { | ||
return fmt.Errorf(te.msg) | ||
} | ||
|
||
func (te TplError) Msg() string { | ||
return te.msg | ||
} | ||
|
||
func (te TplError) ExitCode() int { | ||
return te.exitCode | ||
} | ||
|
||
var NO_CONFIG_FILE_ERR = TplError{ | ||
msg: "No config file found", | ||
exitCode: 1, | ||
} | ||
|
||
var NO_FUNC_NAME_ERR = TplError{ | ||
msg: "No function name provided", | ||
exitCode: 2, | ||
} | ||
var NO_FUNC_FOUND_ERR = TplError{ | ||
msg: "Function not found in config", | ||
exitCode: 3, | ||
} | ||
|
||
var INVALID_CONFIG_ERR = TplError{ | ||
msg: "Invalid config file", | ||
exitCode: 4, | ||
} | ||
|
||
var INVALID_RESP_CODE = TplError{ | ||
msg: "Invalid response code", | ||
exitCode: 5, | ||
} | ||
var FAILED_TO_GET_DATA = TplError{ | ||
msg: "Failed to get data", | ||
exitCode: 6, | ||
} | ||
var FAILED_TO_MAKE_HTTP_CALL = TplError{ | ||
msg: "Failed to make http call", | ||
exitCode: 7, | ||
} | ||
var FAILED_TO_PARSE_JSON = TplError{ | ||
msg: "Failed to parse JSON", | ||
exitCode: 8, | ||
} | ||
var FAILED_TO_PARSE_OUTPUT_FIELD = TplError{ | ||
msg: "Failed to parse output field", | ||
exitCode: 9, | ||
} |
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