增加ToError方法

This commit is contained in:
zhangdeman001 2023-05-11 18:20:56 +08:00
parent 0679ce5092
commit 2bc6061e1c
4 changed files with 29 additions and 39 deletions

View File

@ -7,6 +7,7 @@
<list default="true" id="0c7a619f-b520-4d41-ab0d-cfa1799d3cdf" name="Changes" comment=""> <list default="true" id="0c7a619f-b520-4d41-ab0d-cfa1799d3cdf" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/abstrace.go" beforeDir="false" afterPath="$PROJECT_DIR$/abstrace.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/abstrace.go" beforeDir="false" afterPath="$PROJECT_DIR$/abstrace.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/exception.go" beforeDir="false" afterPath="$PROJECT_DIR$/exception.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/exception.go" beforeDir="false" afterPath="$PROJECT_DIR$/exception.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -20,7 +21,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="GOROOT" url="file://$USER_HOME$/go/go1.17.11" /> <component name="GOROOT" url="file:///usr/local/opt/go/libexec" />
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
@ -35,46 +36,27 @@
<component name="GoLibraries"> <component name="GoLibraries">
<option name="indexEntireGoPath" value="false" /> <option name="indexEntireGoPath" value="false" />
</component> </component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2B4P2ryw4H3y3GlDs3w9wFxFqHs" /> <component name="ProjectId" id="2B4P2ryw4H3y3GlDs3w9wFxFqHs" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent"><![CDATA[{
<property name="DefaultGoTemplateProperty" value="Go File" /> "keyToString": {
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> "RunOnceActivity.OpenProjectViewOnStart": "true",
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> "RunOnceActivity.ShowReadmeOnStart": "true",
<property name="WebServerToolWindowFactoryState" value="false" /> "RunOnceActivity.go.formatter.settings.were.checked": "true",
<property name="go.formatter.settings.were.checked" value="true" /> "RunOnceActivity.go.migrated.go.modules.settings": "true",
<property name="go.import.settings.migrated" value="true" /> "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
<property name="go.modules.go.list.on.any.changes.was.set" value="true" /> "WebServerToolWindowFactoryState": "false",
<property name="go.sdk.automatically.set" value="true" /> "go.import.settings.migrated": "true",
<property name="last_opened_file_path" value="$USER_HOME$" /> "go.sdk.automatically.set": "true",
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> "last_opened_file_path": "/Users/zhangdeman"
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> }
<property name="settings.editor.selected.configurable" value="watcher.settings" /> }]]></component>
</component>
<component name="RunManager">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="exception" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="exception" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" /> <option name="version" value="3" />
@ -89,9 +71,8 @@
</entry> </entry>
</map> </map>
</option> </option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<integration-enabled>true</integration-enabled> <settings-migrated>true</settings-migrated>
</component> </component>
</project> </project>

View File

@ -23,4 +23,6 @@ type IException interface {
GetData() interface{} GetData() interface{}
// GetHttpCode *获取当前异常要返回的http状态码, 不设置则 默认 200 // GetHttpCode *获取当前异常要返回的http状态码, 不设置则 默认 200
GetHttpCode() int GetHttpCode() int
// ToError 转换为内置error类型
ToError() error
} }

View File

@ -41,6 +41,13 @@ func (e *Exception) GetHttpCode() int {
return e.httpCode return e.httpCode
} }
func (e *Exception) ToError() error {
if nil == e {
return nil
}
return errors.New(e.Error())
}
// NewWithCode 仅使用错误码实例化异常 // NewWithCode 仅使用错误码实例化异常
// //
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>

2
go.mod
View File

@ -1,3 +1,3 @@
module git.zhangdeman.cn/zhangdeman/exception module git.zhangdeman.cn/zhangdeman/exception
go 1.17 go 1.20