add error code for components

This commit is contained in:
John Guo
2021-07-20 23:02:02 +08:00
parent f72d991c36
commit 0ddacdd7e2
88 changed files with 434 additions and 263 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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