go mod dowload
go run main.gocurl --location --request POST 'http://localhost:8080/api' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "some-id",
"fail_database": false,
"fail_service": false
}'There are two errors struct: database.Err and service.Err.
They implement error interface Error() string and Is(target error) bool,
returning true if target is pkg.InternalErr.
The middleware ErrorHandlerMiddleware() get the errors from gin-gonic context.
If present, check if it is a pkg.InternalErr.
Case true, return an internal server error; otherwise, return bad request.
This middleware also checks if err.Err is a database.Err and prints additional logs.
The api.Handler call run c.Error(err) to append errors in gin-gonic context.