From 0f67559995c5ae80d5bd5adb7dd1cd817a94f482 Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 10 Jan 2022 22:58:29 +0800 Subject: [PATCH] add gcode.WithCode --- errors/gcode/gcode.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/errors/gcode/gcode.go b/errors/gcode/gcode.go index 8665b8a27..6f96eee8f 100644 --- a/errors/gcode/gcode.go +++ b/errors/gcode/gcode.go @@ -57,3 +57,13 @@ func New(code int, message string, detail interface{}) Code { detail: detail, } } + +// WithCode creates and returns a new error code based on given Code. +// The code and message is from given `code`, but the detail if from given `detail`. +func WithCode(code Code, detail interface{}) Code { + return localCode{ + code: code.Code(), + message: code.Message(), + detail: detail, + } +}