2022-04-12 15:45:26 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gerror
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Code returns the error code.
|
|
|
|
// It returns CodeNil if it has no error code.
|
|
|
|
func (err *Error) Code() gcode.Code {
|
|
|
|
if err == nil {
|
|
|
|
return gcode.CodeNil
|
|
|
|
}
|
|
|
|
if err.code == gcode.CodeNil {
|
2022-07-15 10:49:04 +08:00
|
|
|
return Code(err.Unwrap())
|
2022-04-12 15:45:26 +08:00
|
|
|
}
|
|
|
|
return err.code
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCode updates the internal code with given code.
|
|
|
|
func (err *Error) SetCode(code gcode.Code) {
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err.code = code
|
|
|
|
}
|