POST:/users works

This commit is contained in:
2022-11-18 21:25:40 +01:00
parent 34a27d9ca4
commit 5991631bfa
44 changed files with 2131 additions and 737 deletions

View File

@@ -1,14 +1,9 @@
package ginresp
type sendAPIError struct {
type apiError struct {
Success bool `json:"success"`
Error int `json:"error"`
ErrorHighlight int `json:"errhighlight"`
Message string `json:"message"`
}
type internAPIError struct {
Success bool `json:"success"`
ErrorID int `json:"errid,omitempty"`
Message string `json:"message"`
RawError error `json:"errorObject,omitempty"`
}

View File

@@ -1,6 +0,0 @@
package ginresp
type errBody struct {
Success bool `json:"success"`
Message string `json:"message"`
}

View File

@@ -1,13 +1,14 @@
package ginresp
import (
scn "blackforestbytes.com/simplecloudnotifier"
"blackforestbytes.com/simplecloudnotifier/api/apierr"
"github.com/gin-gonic/gin"
"net/http"
)
type HTTPResponse interface {
Write(context *gin.Context)
Write(g *gin.Context)
}
type jsonHTTPResponse struct {
@@ -73,13 +74,21 @@ func Text(sc int, data string) HTTPResponse {
}
func InternalError(e error) HTTPResponse {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: errBody{Success: false, Message: e.Error()}}
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: apiError{Success: false, Error: int(apierr.INTERNAL_EXCEPTION), Message: e.Error()}}
}
func InternAPIError(errid int, msg string) HTTPResponse {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: internAPIError{Success: false, ErrorID: errid, Message: msg}}
func InternAPIError(errorid apierr.APIError, msg string, e error) HTTPResponse {
if scn.Conf.ReturnRawErrors {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: apiError{Success: false, Error: int(errorid), Message: msg, RawError: e}}
} else {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: apiError{Success: false, Error: int(errorid), Message: msg}}
}
}
func SendAPIError(errorid apierr.APIError, highlight int, msg string) HTTPResponse {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: sendAPIError{Success: false, Error: int(errorid), ErrorHighlight: highlight, Message: msg}}
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: apiError{Success: false, Error: int(errorid), ErrorHighlight: highlight, Message: msg}}
}
func NotImplemented() HTTPResponse {
return &errHTTPResponse{statusCode: http.StatusInternalServerError, data: apiError{Success: false, Error: -1, ErrorHighlight: 0, Message: "Not Implemented"}}
}

View File

@@ -6,15 +6,15 @@ type WHandlerFunc func(*gin.Context) HTTPResponse
func Wrap(fn WHandlerFunc) gin.HandlerFunc {
return func(context *gin.Context) {
return func(g *gin.Context) {
wrap := fn(context)
wrap := fn(g)
if context.Writer.Written() {
if g.Writer.Written() {
panic("Writing in WrapperFunc is not supported")
}
wrap.Write(context)
wrap.Write(g)
}