Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
github.com/kucjac/uni-db
Package unidb contains unified database Errors converted from third-party package errors.
In order to create the RESTful API that is indepenedent of the database type, the database errors must be converted into single form. This package defines database Errors with some Prototypes that are the most common error categories.
// Unified database error
type Error struct {
ID uint
Title string
Message string
}
// database error prototypes
var (
...
ErrIntegrityConstViolation = Error{
ID: 6,
Title: "Integrity constraint violation",
}
...
)
In order to maintaing uniform form of the error converting, every database driver should implement the 'Converter' interface with it's custom error converter.
// Converter interface
type Converter interface {
Convert(err error) *unidb.Error
}
...
type CustomConverter struct {
// Contains some kind of error mapper
// from custom errors into unidb.ErrPrototype
}
func (c *CustomConverter) Convert(err error) *unidb.Error {
// get unidb.ErrPrototype from the mapping and
// create new *unidb.Error on it's base
customErr := err.(CustomErrorType)
proto, ok := mapping[customErr]
if !ok {
return unidb.ErrUnspecifiedError.New()
}
return proto.New()
}
...
Good examples on how to write error converters are the converters defined in the mysqlconv, pgconv, sqliteconv or gormconv packages.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.