Commit af93cfe5 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

refactored cast errors to use a util

parent d574d03a
......@@ -3,7 +3,6 @@ package http
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
......@@ -11,10 +10,9 @@ import (
"strings"
cmds "github.com/jbenet/go-ipfs/commands"
u "github.com/jbenet/go-ipfs/util"
)
var castError = errors.New("cast error")
const (
ApiUrlFormat = "http://%s%s/%s?%s"
ApiPath = "/api/v0" // TODO: make configurable
......@@ -70,7 +68,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
for k, v := range req.Options() {
str, ok := v.(string)
if !ok {
return "", nil, castError
return "", nil, u.ErrCast()
}
query.Set(k, str)
}
......@@ -87,7 +85,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
if argDef.Type == cmds.ArgString {
str, ok := arg.(string)
if !ok {
return "", nil, castError
return "", nil, u.ErrCast()
}
query.Add("arg", str)
......@@ -99,7 +97,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
var ok bool
inputStream, ok = arg.(io.Reader)
if !ok {
return "", nil, castError
return "", nil, u.ErrCast()
}
}
}
......
package commands
import (
"errors"
"fmt"
"io"
"reflect"
......@@ -9,6 +8,7 @@ import (
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
type optMap map[string]interface{}
......@@ -176,7 +176,7 @@ func (r *request) ConvertOptions() error {
convert := converters[opt.Type]
str, ok := v.(string)
if !ok {
return errors.New("cast error")
return u.ErrCast()
}
val, err := convert(str)
if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment