Skip to content

Commit c4972b6

Browse files
committed
Enhance error output and codes
Return 400 on user errors when adding certs Enhance 'port in use' error output Resolves #34 #36 #37
1 parent 0153437 commit c4972b6

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

api/api.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ var (
5858
BodyReadFail = errors.New("Body Read Failed")
5959
NoServerError = errors.New("No Server Found")
6060
NoServiceError = errors.New("No Service Found")
61-
BadListenAddr = errors.New("Port Already In Use")
6261
)
6362

6463
type (

api/certificate.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"net/http"
5+
"strings"
56

67
"github.com/nanopack/portal/cluster"
78
"github.com/nanopack/portal/core"
@@ -19,6 +20,14 @@ func postCert(rw http.ResponseWriter, req *http.Request) {
1920
// save to cluster
2021
err = cluster.SetCert(cert)
2122
if err != nil {
23+
if strings.Contains(err.Error(), "tls: failed to find any PEM data in certificate input") {
24+
writeError(rw, req, err, http.StatusBadRequest)
25+
return
26+
}
27+
if strings.Contains(err.Error(), "asn1: syntax error: PrintableString contains invalid character") {
28+
writeError(rw, req, err, http.StatusBadRequest)
29+
return
30+
}
2231
writeError(rw, req, err, http.StatusInternalServerError)
2332
return
2433
}

api/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ func checkPort(svc core.Service) error {
7070
// assume tls/http listening same ip. if listen on all interfaces, break on ports
7171
if svc.Port == hPort || svc.Port == tPort || svc.Port == aPort {
7272
if listenHttp[0] == "" || listenHttp[0] == "0.0.0.0" {
73-
return BadListenAddr
73+
return fmt.Errorf("Socket in use: '%s:%d'", listenHttp[0], svc.Port)
7474
}
7575
if svc.Host == listenHttp[0] || svc.Host == listenTls[0] || svc.Host == config.ApiHost {
76-
return BadListenAddr
76+
return fmt.Errorf("Socket in use: '%s:%d'", svc.Host, svc.Port)
7777
}
7878
}
7979

scripts/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ getCurrTag() {
2121

2222
# build portal
2323
echo "Building portal..."
24-
# export GOROOT="/usr/local/go-1.7.5/"
25-
# export PATH=/usr/local/go-1.7.5/bin:$PATH
24+
# export GOROOT="/usr/local/go-1.7.6"
25+
# export PATH=/usr/local/go-1.7.6/bin:$PATH
2626

2727
# should be built with go1.7.x until tls regression is resolved. also https://github.com/golang/go/issues/21133
2828
gox -ldflags="-s -X github.com/nanopack/portal/commands.tag=$(getCurrTag)

vendor/vendor.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@
159159
"revisionTime": "2017-03-27T21:44:30Z"
160160
},
161161
{
162-
"checksumSHA1": "b1ptZ969lQ2ZxRIZhP12pmY+P8w=",
162+
"checksumSHA1": "B0xFOAo+jHUmUX7nmdPCFClwxJ0=",
163163
"path": "github.com/nanobox-io/nanobox-router",
164-
"revision": "5d5e7a6d0cae8d846c275c49f16398135e9112dd",
165-
"revisionTime": "2017-09-08T15:51:10Z"
164+
"revision": "8cb764136ffa4b96c430a6f15ebd362ac0cfa26b",
165+
"revisionTime": "2017-09-08T21:39:15Z"
166166
},
167167
{
168168
"checksumSHA1": "65+hx0QlLzpWe5pnjAzteKBnC10=",

0 commit comments

Comments
 (0)