GithubHelp home page GithubHelp logo

errors's Introduction

エラー機構

エラーの処理を共通化するための参考実装です。

使い方

このerrorsパッケージを自身アプリケーション以下にコピーしてください。

├── src
│   ├── api
│   ├── app
│   ├── domain
│   └── infra
└── errors ←

定義する方法

新しいエラーは define_xxx.go に定義してください

var エラー定義名 = newXXX(エラーコード, メッセージ)
var (
    ErrInvalid = newBadRequest("invalid", "ユーザ側のエラーです")
    ErrSystem = newInternalServerError("system", "サーバ側のエラーです")
)

呼び出す方法

ラップしたい場合

if err := Update(); err != nil {
    return errors.Wrap(err)
}

or  (独自で定義したエラーを使う)
if err != nil {
    return errors.UpdateUserData.Wrap(err, "UpdateUserData")
}

新しくエラーを発生させたい場合

if device != `` {
    return errors.New("unknown device")
}

or

if device != `` {
    return errors.Errorf("AuthService device != ``")
}

or

if device != `` {
    return errors.InvalidDevice.New("AuthService device != ``")
}

エラーコード表

errors's People

Contributors

kentokento avatar satorunooshie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

satorunooshie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.