Skip to content

Loopmaas/loop-err

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cus Error

Usage

Create a CusErr

func foo() *loop_err.CusError {
    // Case 1.
   cusErr := loop_err.New(loop_err.InternalServerError, "Your error message")

   // Case 2: New a loop_err with other error
   otherErr := someService()
   cusErr = loop_err.New(loop_err.InternalServerError, "Your error message",otherErr)

   return cusErr
}

Compare with cusCode

func foo() {
    cusErr := loop_err.New(loop_err.InternalServerError, "Your error message")
    if cusErr.Code() == loop_err.InternalServerError {
        // Do something...
    }
}

Log a cusError

func foo(ctx context.Context) {
    cusErr := loop_err.New(loop_err.InternalServerError, "Your error message")

    // If you want some field to log also, use `NewField()` to record with your err
    cus_otel.Error(ctx, err.Message(), cus_otel.NewField("token", req.AccessToken))

    // Or you can just send log simply
    cus_otel.Error(ctx, err.Error())
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

3 watching

Forks

Packages

 
 
 

Contributors