fix(media): handle some errors

This commit is contained in:
Mathis Maquenne
2024-10-14 16:22:44 +02:00
parent 6d660e3f51
commit cc16b17b88
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -17,6 +17,7 @@ type Media struct {
Format string `json:"format"` Format string `json:"format"`
Sources []Source `json:"sources"` Sources []Source `json:"sources"`
} }
Errors []MediaError `json:"errors"`
} `json:"data"` } `json:"data"`
} }
+7
View File
@@ -68,6 +68,13 @@ func (s *Song) GetMediaData(quality string) (*Media, error) {
return nil, fmt.Errorf("%s", media.Errors[0].Message) return nil, fmt.Errorf("%s", media.Errors[0].Message)
} }
if len(media.Data) > 0 && len(media.Data[0].Errors) > 0 {
if media.Data[0].Errors[0].Code == 2002 {
return nil, fmt.Errorf("invalid track token")
}
return nil, fmt.Errorf("%s", media.Data[0].Errors[0].Message)
}
return &media, nil return &media, nil
} }