style(backend): improve error handling
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"tanabata/internal/domain"
|
||||
@@ -17,28 +16,28 @@ type ErrorMapper struct{}
|
||||
|
||||
func (m *ErrorMapper) MapError(err domain.DomainError) (int, ErrorResponse) {
|
||||
switch err.Code {
|
||||
case domain.ErrFileNotFound:
|
||||
case domain.ErrCodeFileNotFound:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "Not Found",
|
||||
Code: string(err.Code),
|
||||
Message: fmt.Sprintf("File %q not found", err.Details...),
|
||||
Message: err.Message,
|
||||
}
|
||||
case domain.ErrMIMENotSupported:
|
||||
case domain.ErrCodeMIMENotSupported:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "MIME not supported",
|
||||
Code: string(err.Code),
|
||||
Message: fmt.Sprintf("MIME not supported: %q", err.Details...),
|
||||
Message: err.Message,
|
||||
}
|
||||
case domain.ErrValidation:
|
||||
case domain.ErrCodeBadRequest:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Code: string(err.Code),
|
||||
Message: fmt.Sprintf("Invalid %s: %s", err.Details...),
|
||||
Message: err.Message,
|
||||
}
|
||||
}
|
||||
return http.StatusInternalServerError, ErrorResponse{
|
||||
Error: "Internal Server Error",
|
||||
Code: string(err.Code),
|
||||
Message: "An unexpected error occured",
|
||||
Message: err.Message,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user