check response code in publisher

This commit is contained in:
Asim Aslam
2021-06-01 15:09:24 +01:00
parent 3f0e1364f9
commit be790b28cc

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
@@ -46,6 +47,12 @@ func publishAPI(apiSpec *PublicAPI) error {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
b, _ := ioutil.ReadAll(resp.Body)
return errors.New(string(b))
}
io.Copy(ioutil.Discard, resp.Body)
return nil