Implement fetch
action, normalize error response params (#13)
This commit is contained in:
@@ -52,6 +52,16 @@ func MakeListResponse() *ListResponse {
|
||||
}
|
||||
}
|
||||
|
||||
// FetchResponse a response format for the "fetch" request
|
||||
type FetchResponse struct {
|
||||
Contents string `json:"contents"`
|
||||
}
|
||||
|
||||
// MakeFetchResponse initializes an empty fetch response
|
||||
func MakeFetchResponse() *FetchResponse {
|
||||
return &FetchResponse{}
|
||||
}
|
||||
|
||||
// SendOk sends a success response to the browser extension in the predefined json format
|
||||
func SendOk(data interface{}) {
|
||||
send(&okResponse{
|
||||
@@ -61,22 +71,16 @@ func SendOk(data interface{}) {
|
||||
})
|
||||
}
|
||||
|
||||
// SendError sends an error response to the browser extension in the predefined json format
|
||||
func SendError(errorCode errors.Code, errorMsg string, extraParams *map[string]string) {
|
||||
params := map[string]string{
|
||||
"message": errorMsg,
|
||||
}
|
||||
if extraParams != nil {
|
||||
for key, value := range *extraParams {
|
||||
params[key] = value
|
||||
}
|
||||
}
|
||||
// SendErrorAndExit sends an error response to the browser extension in the predefined json format and exits with the specified exit code
|
||||
func SendErrorAndExit(errorCode errors.Code, params *map[errors.Field]string) {
|
||||
send(&errorResponse{
|
||||
Status: "error",
|
||||
Code: errorCode,
|
||||
Version: version.Code,
|
||||
Params: params,
|
||||
})
|
||||
|
||||
errors.ExitWithCode(errorCode)
|
||||
}
|
||||
|
||||
func send(data interface{}) {
|
||||
|
Reference in New Issue
Block a user