@@ -43,15 +43,19 @@ type ErrAttachmentSizeExceed struct {
4343 Size int64
4444}
4545
46- func (e * ErrAttachmentSizeExceed ) Error () string {
46+ func (e ErrAttachmentSizeExceed ) Error () string {
4747 return fmt .Sprintf ("attachment size %d exceed limit %d" , e .Size , e .MaxSize )
4848}
4949
5050func IsErrAttachmentSizeExceed (err error ) bool {
51- _ , ok := err .(* ErrAttachmentSizeExceed )
51+ _ , ok := err .(ErrAttachmentSizeExceed )
5252 return ok
5353}
5454
55+ func (err ErrAttachmentSizeExceed ) Unwrap () error {
56+ return util .ErrInvalidArgument
57+ }
58+
5559// UploadAttachment upload new attachment into storage and update database
5660func UploadAttachment (ctx context.Context , file io.Reader , allowedTypes string , maxFileSize , fileSize int64 , attach * repo_model.Attachment ) (* repo_model.Attachment , error ) {
5761 buf := make ([]byte , 1024 )
@@ -63,7 +67,7 @@ func UploadAttachment(ctx context.Context, file io.Reader, allowedTypes string,
6367 }
6468
6569 if maxFileSize >= 0 && fileSize > (maxFileSize ) {
66- return nil , & ErrAttachmentSizeExceed {MaxSize : maxFileSize , Size : fileSize }
70+ return nil , ErrAttachmentSizeExceed {MaxSize : maxFileSize , Size : fileSize }
6771 }
6872
6973 return NewAttachment (ctx , attach , io .MultiReader (bytes .NewReader (buf ), file ), fileSize )
0 commit comments