github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/design/framework/errors.md (about)

     1  # Errors
     2  
     3  Micro provides its own form of structured errors to add detail to otherwise opaque strings.
     4  
     5  ## Overview
     6  
     7  Structured errors enable us to give an error an ID, code, and detail. This is useful when 
     8  debugging a layered stack especially related to microservices. We want to evolve these 
     9  structured errors into something more widely applicable beyond RPC.
    10  
    11  ## Design
    12  
    13  The current design
    14  
    15  ```go
    16  type Error struct {
    17  	Id                   string
    18  	Code                 int32
    19  	Detail               string
    20  	Status               string
    21  }
    22  
    23  func (e *Error) Error() string {
    24  	b, _ := json.Marshal(e)
    25  	return string(b)
    26  }
    27  ```
    28  
    29  Find the current implementation in [github.com/micro/go-micro/v2/errors](https://github.com/micro/go-micro/blob/master/errors/errors.go)
    30  
    31  When output the error appears in json format
    32  
    33  ```
    34  {"id": "go.micro.client", "code": 500, "detail": "an error occurred calling the service", "status": "internal server error"}
    35  ```
    36  
    37  These errors are passed via the `Micro-Error` header or in grpc encapsulated within their error type.