Skip to content

Commit

Permalink
Merge pull request #15 from Moranilt/feature/handler-errors
Browse files Browse the repository at this point in the history
feat: change type of handler error
  • Loading branch information
Moranilt committed Mar 19, 2024
2 parents b711dd9 + e54a87f commit 5072707
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"context"
"encoding/json"
"errors"
"mime/multipart"
"net/http"
"strings"
Expand All @@ -20,13 +19,17 @@ const (
ErrEmptyMultipartData = "empty multipart form data "
)

const (
ERR_CODE_UnexpectedBody = 999
)

type HandlerMaker[ReqT any, RespT any] struct {
request *http.Request
response http.ResponseWriter
requestBody ReqT
logger logger.Logger
caller CallerFunc[ReqT, RespT]
err error
err tiny_errors.ErrorHandler
}

// A function that is called to process request.
Expand All @@ -49,7 +52,7 @@ func New[ReqT any, RespT any](w http.ResponseWriter, r *http.Request, logger log
}

func (h *HandlerMaker[ReqT, RespT]) setError(errs ...string) {
h.err = errors.New(strings.Join(errs, ","))
h.err = tiny_errors.New(ERR_CODE_UnexpectedBody, tiny_errors.Message(strings.Join(errs, ",")))
}

// Parsing JSON-body of request.
Expand Down

0 comments on commit 5072707

Please sign in to comment.