forked from mtusi2026/mtusi2026lab4
test(attachments): add upload tests
This commit is contained in:
@@ -51,7 +51,7 @@ func (h *AttachmentHandler) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
var maxBytesErr *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesErr) {
|
||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
|
||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodePayloadTooLarge, "file too large", requestID)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ func (h *AttachmentHandler) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
att, err := h.service.Upload(r.Context(), userID, chatID, req.Filename, body, contentType)
|
||||
switch {
|
||||
case errors.Is(err, service.ErrInvalidSize):
|
||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
|
||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodePayloadTooLarge, "file too large", requestID)
|
||||
return
|
||||
case errors.Is(err, service.ErrInvalidImage):
|
||||
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeInvalidRequest, "invalid image", requestID)
|
||||
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeUnsupportedMediaType, "invalid image", requestID)
|
||||
return
|
||||
case errors.Is(err, service.ErrAttachmentNotFound):
|
||||
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
||||
|
||||
Reference in New Issue
Block a user