-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: define repository and service error (#40)
- Loading branch information
1 parent
08978f3
commit 46969b2
Showing
11 changed files
with
194 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package domain | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
) | ||
|
||
type UserIdObject struct { | ||
value string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package repository | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type ErrorCode string | ||
|
||
const ( | ||
ReadFailurePanic ErrorCode = "read failure" | ||
WriteFailurePanic ErrorCode = "write failure" | ||
) | ||
|
||
type Error struct { | ||
code ErrorCode | ||
err error | ||
} | ||
|
||
func Errorf(code ErrorCode, format string, args ...any) *Error { | ||
return &Error{code: code, err: fmt.Errorf(format, args...)} | ||
} | ||
|
||
func (e Error) Error() string { | ||
return fmt.Sprintf("%s: %s", e.code, e.err.Error()) | ||
} | ||
|
||
func (e Error) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
func (e Error) Code() ErrorCode { | ||
return e.code | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type ErrorCode string | ||
|
||
const ( | ||
DomainFailurePanic ErrorCode = "domain failure" | ||
RepositoryFailurePanic ErrorCode = "repository failure" | ||
) | ||
|
||
type Error struct { | ||
code ErrorCode | ||
err error | ||
} | ||
|
||
func Errorf(code ErrorCode, format string, args ...any) *Error { | ||
return &Error{code: code, err: fmt.Errorf(format, args...)} | ||
} | ||
|
||
func (e Error) Error() string { | ||
return fmt.Sprintf("%s: %s", e.code, e.err.Error()) | ||
} | ||
|
||
func (e Error) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
func (e Error) Code() ErrorCode { | ||
return e.code | ||
} |
Oops, something went wrong.