File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
modules/song-upload/components/client/context Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,16 @@ export const getTokenLocal = (): string | never => {
88 ?. split ( '=' ) [ 1 ] ;
99
1010 // TODO: should be changed to a redirect to the login page?
11- if ( ! token ) throw new Error ( 'Failed to get token ') ;
11+ if ( ! token ) throw new InvalidTokenError ( 'Token not found ') ;
1212
1313 return token ;
1414} ;
15+
16+ export class InvalidTokenError extends Error {
17+ constructor ( msg : string ) {
18+ super ( msg ) ;
19+
20+ // Set the prototype explicitly.
21+ Object . setPrototypeOf ( this , InvalidTokenError . prototype ) ;
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ import {
1515import { toast } from 'react-hot-toast' ;
1616
1717import axiosInstance from '@web/src/lib/axios' ;
18- import { getTokenLocal } from '@web/src/lib/axios/token.utils' ;
18+ import {
19+ InvalidTokenError ,
20+ getTokenLocal ,
21+ } from '@web/src/lib/axios/token.utils' ;
1922
2023import {
2124 UploadSongForm ,
@@ -146,9 +149,15 @@ export const UploadSongProvider = ({
146149 } catch ( e ) {
147150 console . error ( 'Error submitting song' , e ) ;
148151
149- setSendError (
150- 'An unknown error occurred while submitting the song! Please contact us.' ,
151- ) ;
152+ if ( e instanceof InvalidTokenError ) {
153+ setSendError (
154+ 'Your session has expired! Please sign in again and try to submit the song.' ,
155+ ) ;
156+ } else {
157+ setSendError (
158+ 'An unknown error occurred while submitting the song! Please contact us.' ,
159+ ) ;
160+ }
152161 } finally {
153162 setIsSubmitting ( false ) ;
154163 }
You can’t perform that action at this time.
0 commit comments