mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-31 10:37:11 -04:00 
			
		
		
		
	* feat(web): SPA * chore: remove unnecessary prune * feat(web): merge with immich-server * Correct method name * fix: bugs, docs, workflows, etc. * chore: keep dockerignore for dev * chore: remove license * fix: expose 2283 --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { HandleClientError } from '@sveltejs/kit';
 | |
| import type { AxiosError, AxiosResponse } from 'axios';
 | |
| 
 | |
| const LOG_PREFIX = '[hooks.client.ts]';
 | |
| const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';
 | |
| 
 | |
| const parseError = (error: unknown) => {
 | |
|   const httpError = error as AxiosError;
 | |
|   const request = httpError?.request as Request & { path: string };
 | |
|   const response = httpError?.response as AxiosResponse<{
 | |
|     message: string;
 | |
|     statusCode: number;
 | |
|     error: string;
 | |
|   }>;
 | |
| 
 | |
|   let code = response?.data?.statusCode || response?.status || httpError.code || '500';
 | |
|   if (response) {
 | |
|     code += ` - ${response.data?.error || response.statusText}`;
 | |
|   }
 | |
| 
 | |
|   if (request && response) {
 | |
|     console.log({
 | |
|       status: response.status,
 | |
|       url: `${request.method} ${request.path}`,
 | |
|       response: response.data || 'No data',
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   return {
 | |
|     message: response?.data?.message || httpError?.message || DEFAULT_MESSAGE,
 | |
|     code,
 | |
|     stack: httpError?.stack,
 | |
|   };
 | |
| };
 | |
| 
 | |
| export const handleError: HandleClientError = ({ error }) => {
 | |
|   const result = parseError(error);
 | |
|   console.error(`${LOG_PREFIX}:handleError ${result.message}`);
 | |
|   return result;
 | |
| };
 |