Task Attachments #104
|
@ -44,6 +44,7 @@ This document describes the different errors Vikunja can return.
|
|||
| 4009 | 404 | The task relation does not exist. |
|
||||
| 4010 | 400 | Cannot relate a task with itself. |
|
||||
| 4011 | 404 | The task attachment does not exist. |
|
||||
| 4012 | 400 | The task attachment is too large. |
|
||||
| 5001 | 404 | The namspace does not exist. |
|
||||
| 5003 | 403 | The user does not have access to the specified namespace. |
|
||||
| 5006 | 400 | The namespace name cannot be empty. |
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/web"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -745,7 +746,7 @@ func IsErrTaskAttachmentDoesNotExist(err error) bool {
|
|||
}
|
||||
|
||||
func (err ErrTaskAttachmentDoesNotExist) Error() string {
|
||||
return fmt.Sprintf("Task Attachment does not exist [TaskID: %d, AttachmentID: %d, FileID: %d]", err.TaskID, err.AttachmentID, err.FileID)
|
||||
return fmt.Sprintf("Task attachment does not exist [TaskID: %d, AttachmentID: %d, FileID: %d]", err.TaskID, err.AttachmentID, err.FileID)
|
||||
}
|
||||
|
||||
// ErrCodeTaskAttachmentDoesNotExist holds the unique world-error code of this error
|
||||
|
@ -760,6 +761,33 @@ func (err ErrTaskAttachmentDoesNotExist) HTTPError() web.HTTPError {
|
|||
}
|
||||
}
|
||||
|
||||
// ErrTaskAttachmentIsTooLarge represents an error where the user tries to relate a task with itself
|
||||
type ErrTaskAttachmentIsTooLarge struct {
|
||||
Size int64
|
||||
}
|
||||
|
||||
// IsErrTaskAttachmentIsTooLarge checks if an error is ErrTaskAttachmentIsTooLarge.
|
||||
func IsErrTaskAttachmentIsTooLarge(err error) bool {
|
||||
_, ok := err.(ErrTaskAttachmentIsTooLarge)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrTaskAttachmentIsTooLarge) Error() string {
|
||||
return fmt.Sprintf("Task attachment is too large [Size: %d]", err.Size)
|
||||
}
|
||||
|
||||
// ErrCodeTaskAttachmentIsTooLarge holds the unique world-error code of this error
|
||||
const ErrCodeTaskAttachmentIsTooLarge = 4012
|
||||
|
||||
// HTTPError holds the http error description
|
||||
func (err ErrTaskAttachmentIsTooLarge) HTTPError() web.HTTPError {
|
||||
return web.HTTPError{
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Code: ErrCodeTaskAttachmentIsTooLarge,
|
||||
Message: fmt.Sprintf("The task attachment exceeds the configured file size of %d bytes, filesize was %d", config.FilesMaxSize.GetInt64(), err.Size),
|
||||
}
|
||||
}
|
||||
|
||||
// =================
|
||||
// Namespace errors
|
||||
// =================
|
||||
|
|
|
@ -52,6 +52,9 @@ func (ta *TaskAttachment) NewAttachment(f io.ReadCloser, realname string, realsi
|
|||
// Store the file
|
||||
file, err := files.Create(f, realname, realsize, a)
|
||||
if err != nil {
|
||||
if files.IsErrFileIsTooLarge(err) {
|
||||
return ErrTaskAttachmentIsTooLarge{Size: realsize}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue