@@ -91,6 +91,7 @@ export class AuthService {
9191 message : 'Failed to authenticate user' ,
9292 logger : this . logger ,
9393 userFriendlyMessage : 'Please check your credentials and try again' ,
94+ statusCode : 401 ,
9495 } ) ;
9596 }
9697
@@ -155,7 +156,9 @@ export class AuthService {
155156 throw new ApplicationError ( {
156157 message : 'User is not authenticated' ,
157158 logger : this . logger ,
158- errorCode : applicationErrorCodes . unauthorized ,
159+ errorCode : applicationErrorCodes . unauthenticated ,
160+ statusCode : 401 ,
161+ userFriendlyMessage : 'You must be logged in to access this service' ,
159162 } ) ;
160163 }
161164 // check if projectId and collectionId are provided exits
@@ -165,6 +168,7 @@ export class AuthService {
165168 message : 'Project not found' ,
166169 logger : this . logger ,
167170 errorCode : applicationErrorCodes . unauthorized ,
171+ statusCode : 403 ,
168172 } ) ;
169173 }
170174 const collectionExist = await this . projectRepository . checkIfCollectionExist (
@@ -176,6 +180,7 @@ export class AuthService {
176180 message : 'Collection not found' ,
177181 logger : this . logger ,
178182 errorCode : applicationErrorCodes . unauthorized ,
183+ statusCode : 403 ,
179184 } ) ;
180185 }
181186 // check if user has permission to write to the collection
@@ -185,6 +190,7 @@ export class AuthService {
185190 message : 'You do not have permission to write in this collection, contact your admin' ,
186191 logger : this . logger ,
187192 errorCode : applicationErrorCodes . unauthorized ,
193+ statusCode : 403 ,
188194 } ) ;
189195 }
190196 const validityPeriod = this . validityFromEnv ? Number ( this . validityFromEnv ) : 6 * 3600 ;
@@ -213,6 +219,7 @@ export class AuthService {
213219 throw new ApplicationError ( {
214220 message : 'You do not have permission to write in this collection, contact your admin' ,
215221 errorCode : applicationErrorCodes . unauthorized ,
222+ statusCode : 403 ,
216223 logger : this . logger ,
217224 } ) ;
218225 }
@@ -225,7 +232,8 @@ export class AuthService {
225232 throw new ApplicationError ( {
226233 message : 'Unsupported auth source' ,
227234 logger : this . logger ,
228- errorCode : applicationErrorCodes . unauthorized ,
235+ errorCode : applicationErrorCodes . unauthenticated ,
236+ statusCode : 401 ,
229237 } ) ;
230238 }
231239 return func ;
@@ -316,7 +324,8 @@ export class AuthService {
316324 throw new ApplicationError ( {
317325 message : 'Invalid or expired API key' ,
318326 logger : this . logger ,
319- errorCode : applicationErrorCodes . unauthorized ,
327+ errorCode : applicationErrorCodes . unauthenticated ,
328+ statusCode : 401 ,
320329 } ) ;
321330 }
322331
@@ -333,7 +342,8 @@ export class AuthService {
333342 throw new ApplicationError ( {
334343 message : 'Invalid JWT' ,
335344 logger : this . logger ,
336- errorCode : applicationErrorCodes . unauthorized ,
345+ errorCode : applicationErrorCodes . unauthenticated ,
346+ statusCode : 401 ,
337347 } ) ;
338348 }
339349
@@ -342,14 +352,16 @@ export class AuthService {
342352 throw new ApplicationError ( {
343353 message : 'Invalid JWT - purpose ws server' ,
344354 logger : this . logger ,
345- errorCode : applicationErrorCodes . unauthorized ,
355+ errorCode : applicationErrorCodes . unauthenticated ,
356+ statusCode : 401 ,
346357 } ) ;
347358 }
348359 if ( ! payload . userId ) {
349360 throw new ApplicationError ( {
350361 message : 'Invalid JWT - missing user ID' ,
351362 logger : this . logger ,
352- errorCode : applicationErrorCodes . unauthorized ,
363+ errorCode : applicationErrorCodes . unauthenticated ,
364+ statusCode : 401 ,
353365 } ) ;
354366 }
355367
@@ -369,6 +381,7 @@ export class AuthService {
369381 message : 'Invalid auth data' ,
370382 logger : this . logger ,
371383 errorCode : applicationErrorCodes . unauthenticated ,
384+ statusCode : 401 ,
372385 } ) ;
373386 }
374387
@@ -379,6 +392,7 @@ export class AuthService {
379392 message : 'Invalid Firebase ID Token' ,
380393 errorCode : applicationErrorCodes . unauthenticated ,
381394 logger : this . logger ,
395+ statusCode : 401 ,
382396 } ) ;
383397 }
384398
@@ -407,6 +421,7 @@ export class AuthService {
407421 message : 'Invalid auth data' ,
408422 logger : this . logger ,
409423 errorCode : applicationErrorCodes . unauthenticated ,
424+ statusCode : 401 ,
410425 } ) ;
411426 }
412427
@@ -417,6 +432,7 @@ export class AuthService {
417432 message : 'Invalid Firebase ID Token' ,
418433 errorCode : applicationErrorCodes . unauthenticated ,
419434 logger : this . logger ,
435+ statusCode : 401 ,
420436 } ) ;
421437 }
422438
0 commit comments