mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Use content-type to tell unexpected errors from good ones apart.
This commit is contained in:
parent
82feb18eef
commit
7cb376dd0e
1 changed files with 11 additions and 1 deletions
|
|
@ -15,11 +15,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ProtonMail/gopenpgp/v2/armor"
|
"github.com/ProtonMail/gopenpgp/v2/armor"
|
||||||
"github.com/ProtonMail/gopenpgp/v2/constants"
|
"github.com/ProtonMail/gopenpgp/v2/constants"
|
||||||
|
|
@ -301,6 +303,15 @@ func (p *processor) process(filename string) error {
|
||||||
fmt.Printf("HTTPS %s\n", uploadErr)
|
fmt.Printf("HTTPS %s\n", uploadErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We expect a JSON answer so all other is not valid.
|
||||||
|
if strings.Contains(resp.Header.Get("Content-Type"), "application/json") {
|
||||||
|
var sb strings.Builder
|
||||||
|
if _, err := io.Copy(&sb, resp.Body); err != nil {
|
||||||
|
return fmt.Errorf("reading none JSON reply from server failed: %v", err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("none JSON replay: %v", sb.String())
|
||||||
|
}
|
||||||
|
|
||||||
var result struct {
|
var result struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ReleaseDate string `json:"release_date"`
|
ReleaseDate string `json:"release_date"`
|
||||||
|
|
@ -309,7 +320,6 @@ func (p *processor) process(filename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
err := errors.New("Error: view server logs for details")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue