mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-24 02:29:05 +02:00
refactor: standardize API error handling (#1635)
This commit is contained in:
@@ -2,6 +2,7 @@ package profilepicture
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
@@ -19,6 +20,8 @@ import (
|
||||
|
||||
const profilePictureSize = 300
|
||||
|
||||
var ErrInvalidImage = errors.New("invalid image")
|
||||
|
||||
// CreateProfilePicture resizes the profile picture to a square and encodes it as PNG
|
||||
func CreateProfilePicture(file io.ReadSeeker) (io.ReadSeeker, error) {
|
||||
// Attempt standard formats first
|
||||
@@ -30,7 +33,10 @@ func CreateProfilePicture(file io.ReadSeeker) (io.ReadSeeker, error) {
|
||||
// Try WebP
|
||||
webpImg, webpErr := webp.Decode(file)
|
||||
if webpErr != nil {
|
||||
return nil, fmt.Errorf("failed to decode image: %w", err)
|
||||
return nil, fmt.Errorf("%w: %w", ErrInvalidImage, errors.Join(
|
||||
fmt.Errorf("standard formats: %w", err),
|
||||
fmt.Errorf("WebP: %w", webpErr),
|
||||
))
|
||||
}
|
||||
|
||||
img = webpImg
|
||||
|
||||
Reference in New Issue
Block a user