All Projects → NeutrinoCorp → ddderr

NeutrinoCorp / ddderr

Licence: MIT license
👺 Reflection-free Domain-Driven errors for Go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to ddderr

Stove
Domain Driven Design oriented application framework, meets CRUD needs
Stars: ✭ 160 (+451.72%)
Mutual labels:  ddd, domain-driven-design
business
Based on the Domain-Driven-Design approach, the business framework will help you structure and implement your business code cleanly and efficiently.
Stars: ✭ 23 (-20.69%)
Mutual labels:  ddd, domain-driven-design
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+458.62%)
Mutual labels:  ddd, domain-driven-design
Eventflow
Async/await first CQRS+ES and DDD framework for .NET
Stars: ✭ 1,932 (+6562.07%)
Mutual labels:  ddd, domain-driven-design
Run Aspnetcore
A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 227 (+682.76%)
Mutual labels:  ddd, domain-driven-design
Laravel Api Templates
Laravel API starter kit collection using different structures.
Stars: ✭ 149 (+413.79%)
Mutual labels:  ddd, domain-driven-design
Kreta
Modern project management solution
Stars: ✭ 177 (+510.34%)
Mutual labels:  ddd, domain-driven-design
Eventflow.example
DDD+CQRS+Event-sourcing examples using EventFlow following CQRS-ES architecture. It is configured with RabbitMQ, MongoDB(Snapshot store), PostgreSQL(Read store), EventStore(GES). It's targeted to .Net Core 2.2 and include docker compose file.
Stars: ✭ 131 (+351.72%)
Mutual labels:  ddd, domain-driven-design
repository
[PHP 7] Implementation and definition of a base Repository in Domain land.
Stars: ✭ 26 (-10.34%)
Mutual labels:  ddd, domain-driven-design
Library
This is a project of a library, driven by real business requirements. We use techniques strongly connected with Domain Driven Design, Behavior-Driven Development, Event Storming, User Story Mapping.
Stars: ✭ 2,685 (+9158.62%)
Mutual labels:  ddd, domain-driven-design
Goes
Go Event Sourcing made easy
Stars: ✭ 144 (+396.55%)
Mutual labels:  ddd, domain-driven-design
tactical-ddd
lightweight helpers that I find myself implementing over and over again related to DDD/Event Sourcing tactical patterns, such as Value Objects, Entities, AggregateRoots, EntityIds etc...
Stars: ✭ 33 (+13.79%)
Mutual labels:  ddd, domain-driven-design
Nlayerappv3
Domain Driven Design (DDD) N-LayeredArchitecture with .Net Core 2
Stars: ✭ 138 (+375.86%)
Mutual labels:  ddd, domain-driven-design
Event Sourcing Jambo
An Hexagonal Architecture with DDD + Aggregates + Event Sourcing using .NET Core, Kafka e MongoDB (Blog Engine)
Stars: ✭ 159 (+448.28%)
Mutual labels:  ddd, domain-driven-design
Todomvc Ddd Cqrs Eventsourcing
Implementation of basic Todo app via tastejs/todomvc in C#/Typescript with eventsourcing, cqrs, and domain driven design
Stars: ✭ 134 (+362.07%)
Mutual labels:  ddd, domain-driven-design
Architecture
.NET 6, ASP.NET Core 6, Entity Framework Core 6, C# 10, Angular 13, Clean Code, SOLID, DDD.
Stars: ✭ 2,285 (+7779.31%)
Mutual labels:  ddd, domain-driven-design
Php Ddd Example
🐘🎯 Hexagonal Architecture + DDD + CQRS in PHP using Symfony 5
Stars: ✭ 1,960 (+6658.62%)
Mutual labels:  ddd, domain-driven-design
Eshoponcontainersddd
Fork of dotnet-architecture/eShopOnContainers in full DDD/CQRS design using my own patterns
Stars: ✭ 126 (+334.48%)
Mutual labels:  ddd, domain-driven-design
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (+513.79%)
Mutual labels:  ddd, domain-driven-design
Dotnet New Caju
Learn Clean Architecture with .NET Core 3.0 🔥
Stars: ✭ 228 (+686.21%)
Mutual labels:  ddd, domain-driven-design

👺 DDD Error

Go Build GoDoc Go Report Card codebeat badge Coverage Status Go Version

DDD Error is a reflection-free Domain-Driven error wrapper made for Go.

Using existing validators such as playground's implementation is overwhelming because tag validation and the need to rewrite descriptions. With DDD Error, you may still use 3rd-party validators or make your own validations in your value objects, entities or aggregates.

In addition, infrastructure exceptions were added so you may be able to catch specific kind of infrastructure errors.

Exceptions descriptions are based on the Google Cloud API Design Guidelines.

DDD Error is compatible with popular error-handling packages such as Hashicorp's go-multierror

In conclusion, DDD Error aims to ease the lack of exception handling in The Go Programming Language by defining a wide selection of common exceptions which happen inside the domain and/or infrastructure layer(s).

Note: DDD Error is dependency-free, it complies with Go's built-in error interface and avoids reflection to increase overall performance.

Installation

Install DDD Error by running the command

go get github.com/neutrinocorp/ddderr/v3

Full documentation is available here

Common Use Cases

  • Implement retry strategy and circuit breaker resiliency patterns by adding Network exception to the whitelist.
  • Not Acknowledging messages from an event bus if got a Network or Infrastructure generic exception.
  • Get an HTTP/gRPC/OpenCensus status code from an error.
  • Implement multiple strategies when an specific (or generic) type of error was thrown in.
  • Fine-grained exception logging on infrastructure layer by using GetParentDescription() function.

Usage

HTTP status codes

Set an HTTP error code depending on the exception.

err := ddderr.NewNotFound("foo")
log.Print(err) // prints: "The resource foo was not found"

if err.IsNotFound() {
  log.Print(http.StatusNotFound) // prints: 404
  return
}

log.Print(http.StatusInternalServerError) // prints: 500

Or use the builtin HTTP utils:

err := ddderr.NewNotFound("foo")
log.Print(err) // prints: "The resource foo was not found"

// HttpError struct is ready to be marshaled using JSON encoding libs
//
// Function accepts the following optional params (specified on the RFC spec):
// - Type
// - Instance
httpErr := ddderr.NewHttpError("", "", err)
// Will output -> If errType param is empty, then HTTP status text is used as type
// (e.g. Not Found, Internal Server Error)
log.Print(httpErr.Type)
// Will output -> 404 as we got a NotFound error type
log.Print(httpErr.Status)
// Will output -> The resource foo was not found
log.Print(httpErr.Detail)

Domain generic exceptions

Create a generic domain exception when other domain errors don't fulfill your requirements.

err := ddderr.NewDomain("generic error title", "foo has returned a generic domain error")
log.Print(err) // prints: "foo has returned a generic domain error"

if err.IsDomain() {
  log.Print(http.StatusBadRequest) // prints: 400
  return
}

log.Print(http.StatusInternalServerError) // prints: 500

Infrastructure generic exceptions

Create a generic infrastructure exception when other infrastructure exceptions don't fulfill your requirements.

msgErr := errors.New("sarama: Apache kafka consumer error")
err := ddderr.NewInfrastructure("generic error title", "error while consuming message from queue").
	AttachParent(msgErr)
log.Print(err) // prints: "error while consuming message from queue"
log.Print(err.Parent()) // prints: "sarama: Apache kafka consumer error"

Implement multiple strategies depending on exception kind

Take an specific action depending on the exception kind.

esErr := errors.New("failed to connect to Elasticsearch host http://127.0.0.1:9300")

err := ddderr.NewRemoteCall("http://127.0.0.1:9300").
	AttachParent(esErr)
log.Print("infrastructure error: ", err)                       // prints "failed to call external resource [http://127.0.0.1:9300]"
log.Print("infrastructure error resource: ", err.Property())       // http://127.0.0.1:9300
log.Print("is domain error: ", err.IsDomain())                 // false
log.Print("is infrastructure error: ", err.IsInfrastructure()) // true
log.Print("infrastructure error parent: ", err.Parent())       // prints "failed to connect to Elasticsearch host http://127.0.0.1:9300"

if err.IsRemoteCall() {
    // implement retry and/or circuit breaker pattern(s)
}

See examples for more details.

Requirements

  • Go version >= 1.13
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].