new error system (+ some quick fixes)

This commit is contained in:
hexlocation 2025-06-14 23:39:20 +02:00
parent 09d8ffa82c
commit c99c202bc8
2 changed files with 92 additions and 36 deletions

66
internal/types/errors.go Normal file
View file

@ -0,0 +1,66 @@
package types
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
)
type StereoError struct {
Code int
StatusCode int
}
func (e *StereoError) Throw(c *gin.Context, err error) {
c.JSON(e.StatusCode, gin.H{
"code": e.Code,
"success": false,
})
if err != nil {
c.Error(err)
} else {
c.Error(errors.New(fmt.Sprintf("Got an error with code: %v", e.Code)))
}
}
var ErrorFileNotFound = StereoError{
Code: 0,
StatusCode: 404,
}
var ErrorReaderOpen = StereoError{
Code: 1,
StatusCode: 500,
}
var ErrorUnauthorized = StereoError{
Code: 2,
StatusCode: 401,
}
var ErrorInvalidParams = StereoError{
Code: 3,
StatusCode: 400,
}
var ErrorEmptyFile = StereoError{
Code: 4,
StatusCode: 400,
}
var ErrorInvalidFile = StereoError{
Code: 5,
StatusCode: 400,
}
var ErrorDatabase = StereoError{
Code: 6,
StatusCode: 500,
}
var ErrorS3 = StereoError{
Code: 7,
StatusCode: 500,
}