github.com/wangyougui/gf/v2@v2.6.5/errors/gerror/gerror_error_code.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gerror
     8  
     9  import (
    10  	"github.com/wangyougui/gf/v2/errors/gcode"
    11  )
    12  
    13  // Code returns the error code.
    14  // It returns CodeNil if it has no error code.
    15  func (err *Error) Code() gcode.Code {
    16  	if err == nil {
    17  		return gcode.CodeNil
    18  	}
    19  	if err.code == gcode.CodeNil {
    20  		return Code(err.Unwrap())
    21  	}
    22  	return err.code
    23  }
    24  
    25  // SetCode updates the internal code with given code.
    26  func (err *Error) SetCode(code gcode.Code) {
    27  	if err == nil {
    28  		return
    29  	}
    30  	err.code = code
    31  }