feat: handler differentiates missing and invalid parameter

This commit is contained in:
Adrien Marquès 2021-06-22 23:43:27 +02:00
parent 3613581b1c
commit ccacd72a36
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
1 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package aicra
import (
"context"
"errors"
"fmt"
"net/http"
"strings"
@ -37,7 +38,11 @@ func (s Handler) resolve(w http.ResponseWriter, r *http.Request) {
// extract request data
var input, err = extractInput(service, *r)
if err != nil {
newResponse().WithError(api.ErrMissingParam).ServeHTTP(w, r)
if errors.Is(err, reqdata.ErrInvalidType) {
newResponse().WithError(api.ErrInvalidParam).ServeHTTP(w, r)
} else {
newResponse().WithError(api.ErrMissingParam).ServeHTTP(w, r)
}
return
}