Error type

What is the best way to return an RPC error?


It is always not easy to define a user-friendly API. However, errors could happen anywhere.

In order to return standard error type to user, it is important to define an error type.

By default, panic middleware/interceptor will be attached which will catch panic and return internal server error as bellow:

Error type used by bootstrapper was defined in rkerror.ErrorResp

func Greeter(ctx *gin.Context) {
	panic("Panic manually!")
        "status":"Internal Server Error",
        "message":"Panic manually!",

Quick start

Return errors

Here is the way how to return errors in user RPC implementation.

func Greeter(ctx *gin.Context) {
	err := rkerror.New(
		rkerror.WithMessage("Trigger manually!"),
		rkerror.WithDetails("This is detail.", false, -1, 0.1))

	ctx.JSON(http.StatusAlreadyReported, err)
$ curl "localhost:8080/v1/greeter?name=rk-dev"
        "status":"Already Reported",
        "message":"Trigger manually!",
            "This is detail.",


Last modified July 12, 2021 : Add chinese version of document (f8db16e)