[NOD-505] Try reading the response in case of upnp error (#576)

This commit is contained in:
Svarog 2020-01-08 17:51:31 +02:00 committed by GitHub
parent 2174a0a7f2
commit 20819ca4cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,13 +35,15 @@ package serverutils
import ( import (
"bytes" "bytes"
"encoding/xml" "encoding/xml"
"github.com/pkg/errors" "io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
) )
// NAT is an interface representing a NAT traversal options for example UPNP or // NAT is an interface representing a NAT traversal options for example UPNP or
@ -313,8 +315,13 @@ func soapRequest(url, function, message string) (replyXML []byte, err error) {
} }
if r.StatusCode >= 400 { if r.StatusCode >= 400 {
// log.Stderr(function, r.StatusCode) data, readErr := ioutil.ReadAll(r.Body)
err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function) if readErr != nil {
err = errors.Wrapf(readErr, "Error %d for %s", r.StatusCode, function)
} else {
err = errors.Errorf("Error %d for %s. Response: %s", r.StatusCode, function, data)
}
r = nil r = nil
return return
} }