package
1.12.6
Repository: https://github.com/go-dev-frame/sponge.git
Documentation: pkg.go.dev

# README

errcode

Error codes usually include system-level error codes and business-level error codes, consisting of a total of 6 decimal digits, e.g. 200101

Error code structure:

First digitMiddle three digitsLast two digits
1 is http system-level error
2 is http business-level error
3 is grpc system-level error
4 is grpc system-level error
Table or module number, range 1~1000Custom number, range 1~100

Error code ranges:

Service TypeSystem-level Error Code RangeBusiness-level Error Code Range
http100000 ~ 200000200000 ~ 300000
grpc300000 ~ 400000400000 ~ 500000

Example of use

Example of http error code usage

Web services created based on SQL, use the following error code:

    import "github.com/go-dev-frame/sponge/pkg/gin/response"

    // return error
    response.Error(c, ecode.InvalidParams)
    // rewrite error messages
    response.Error(c, ecode.InvalidParams.RewriteMsg("custom error message"))

    // convert error code to standard http status code
    response.Out(c, ecode.InvalidParams)
    // convert error code to standard http status code, and rewrite error messages
    response.Out(c, ecode.InvalidParams.RewriteMsg("custom error message"))

Web services created based on Protobuf, use the following error code:

    // return error
    return nil, ecode.InvalidParams.Err()
    // rewrite error messages
    return nil, ecode.InvalidParams.Err("custom error message")

    // convert error code to standard http status code
    return nil, ecode.InvalidParams.ErrToHTTP()
    // convert error code to standard http status code, and rewrite error messages
    return nil, ecode.InvalidParams.ErrToHTTP("custom error message")

Example of grpc error code usage

    // return error
    return nil, ecode.StatusInvalidParams.Err()
    // rewrite error messages
    return nil, ecode.StatusInvalidParams.Err("custom error message")

    // convert error code to standard grpc status code
    return nil, ecode.StatusInvalidParams.ToRPCErr()
    // convert error code to standard grpc status code, and rewrite error messages
    return nil, ecode.StatusInvalidParams.ToRPCErr("custom error message")

    // convert error code to standard http status code
    return nil, ecode.StatusInvalidParams.ErrToHTTP()
    // convert error code to standard http status code, and rewrite error messages
    return nil, ecode.StatusInvalidParams.ErrToHTTP("custom error message")