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
@@ -8,6 +8,9 @@ import (
)
func TestValidateCallbackURLPattern(t *testing.T) {
// #nosec G101
const wildcardUserinfoPattern = "https://user:*@example.com/callback"
tests := []struct {
name string
pattern string
@@ -35,7 +38,7 @@ func TestValidateCallbackURLPattern(t *testing.T) {
},
{
name: "wildcard userinfo",
pattern: "https://user:*@example.com/callback", // #nosec G101 - Test credential
pattern: wildcardUserinfoPattern,
shouldError: false,
},
{
@@ -8,9 +8,9 @@ import (
var AccessTokenCookieName = "__Host-access_token"
var SessionIdCookieName = "__Host-session"
var DeviceTokenCookieName = "__Secure-device_token" //nolint:gosec
var DeviceLoginTokenCookieName = "__Secure-device_login_token" //nolint:gosec
var ReauthenticationTokenCookieName = "__Secure-reauthentication_token" //nolint:gosec
var DeviceTokenCookieName = "__Secure-device_token" // #nosec G101 -- cookie name, not a credential
var DeviceLoginTokenCookieName = "__Secure-device_login_token" // #nosec G101 -- cookie name, not a credential
var ReauthenticationTokenCookieName = "__Secure-reauthentication_token" // #nosec G101 -- cookie name, not a credential
func init() {
if strings.HasPrefix(common.EnvConfig.AppURL, "http://") {
@@ -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