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 echo.Context) error {
	panic("Panic manually!")
    return nil
        "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 echo.Context) error {
	err := rkerror.New(
		rkerror.WithMessage("Trigger manually!"),
		rkerror.WithDetails("This is detail.", false, -1, 0.1))

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


Last modified November 2, 2021 : Add Echo framework documentation (80ec258)