30 lines
610 B
Go
30 lines
610 B
Go
package mailcow
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type MailcowApiResponse struct {
|
|
Type string `json:"type"`
|
|
Msg []string `json:"msg"`
|
|
}
|
|
|
|
// checkApiResponseOK checks if we got a positive response from the Mailcow API.
|
|
//
|
|
// Returns an error detailing why the request failed.
|
|
func checkApiResponseOK(body []byte) error {
|
|
var response []MailcowApiResponse
|
|
|
|
err := json.Unmarshal(body, &response)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to unmarshal body: %w", err)
|
|
}
|
|
|
|
if response[0].Type != "success" {
|
|
return fmt.Errorf("%v", strings.Join(response[0].Msg, " "))
|
|
}
|
|
|
|
return nil
|
|
}
|