refactor: standardize API error handling (#1635)

This commit is contained in:
Elias Schneider
2026-08-02 23:36:06 +02:00
committed by GitHub
parent 281bea54d3
commit 7a4d0dd275
108 changed files with 3163 additions and 1629 deletions
@@ -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