mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
add error code for components
This commit is contained in:
@ -59,11 +59,11 @@ func Convert(dstCharset string, srcCharset string, src string) (dst string, err
|
||||
transform.NewReader(bytes.NewReader([]byte(src)), e.NewDecoder()),
|
||||
)
|
||||
if err != nil {
|
||||
return "", gerror.Newf("%s to utf8 failed. %v", srcCharset, err)
|
||||
return "", gerror.WrapCodef(gerror.CodeInternalError, err, "%s to utf8 failed", srcCharset)
|
||||
}
|
||||
src = string(tmp)
|
||||
} else {
|
||||
return dst, gerror.Newf("unsupport srcCharset: %s", srcCharset)
|
||||
return dst, gerror.NewCodef(gerror.CodeInvalidParameter, "unsupported srcCharset: %s", srcCharset)
|
||||
}
|
||||
}
|
||||
// Do the converting from UTF-8 to <dstCharset>.
|
||||
@ -73,11 +73,11 @@ func Convert(dstCharset string, srcCharset string, src string) (dst string, err
|
||||
transform.NewReader(bytes.NewReader([]byte(src)), e.NewEncoder()),
|
||||
)
|
||||
if err != nil {
|
||||
return "", gerror.Newf("utf to %s failed. %v", dstCharset, err)
|
||||
return "", gerror.WrapCodef(gerror.CodeInternalError, err, "utf to %s failed", dstCharset)
|
||||
}
|
||||
dst = string(tmp)
|
||||
} else {
|
||||
return dst, gerror.Newf("unsupport dstCharset: %s", dstCharset)
|
||||
return dst, gerror.NewCodef(gerror.CodeInvalidParameter, "unsupported dstCharset: %s", dstCharset)
|
||||
}
|
||||
} else {
|
||||
dst = src
|
||||
|
||||
@ -70,7 +70,7 @@ func Decode(data []byte) (res map[string]interface{}, err error) {
|
||||
}
|
||||
|
||||
if haveSection == false {
|
||||
return nil, gerror.New("failed to parse INI file, section not found")
|
||||
return nil, gerror.NewCode(gerror.CodeInvalidParameter, "failed to parse INI file, section not found")
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ func doLoadContentWithOptions(dataType string, data []byte, options Options) (*J
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
err = gerror.New("unsupported type for loading")
|
||||
err = gerror.NewCode(gerror.CodeInvalidParameter, "unsupported type for loading")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user