mirror of
				https://github.com/ItzCrazyKns/Perplexica.git
				synced 2025-11-04 04:38:15 +00:00 
			
		
		
		
	feat(error-object): add key
				
					
				
			This commit is contained in:
		@@ -70,7 +70,8 @@ export const handleConnection = async (
 | 
			
		||||
    ws.send(
 | 
			
		||||
      JSON.stringify({
 | 
			
		||||
        type: 'error',
 | 
			
		||||
        data: 'Invalid LLM or embeddings model selected',
 | 
			
		||||
        data: 'Invalid LLM or embeddings model selected, please refresh the page and try again.',
 | 
			
		||||
        key: 'INVALID_MODEL_SELECTED',
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
    ws.close();
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,13 @@ const handleEmitterEvents = (
 | 
			
		||||
  });
 | 
			
		||||
  emitter.on('error', (data) => {
 | 
			
		||||
    const parsedData = JSON.parse(data);
 | 
			
		||||
    ws.send(JSON.stringify({ type: 'error', data: parsedData.data }));
 | 
			
		||||
    ws.send(
 | 
			
		||||
      JSON.stringify({
 | 
			
		||||
        type: 'error',
 | 
			
		||||
        data: parsedData.data,
 | 
			
		||||
        key: 'CHAIN_ERROR',
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -73,7 +79,11 @@ export const handleMessage = async (
 | 
			
		||||
 | 
			
		||||
    if (!parsedMessage.content)
 | 
			
		||||
      return ws.send(
 | 
			
		||||
        JSON.stringify({ type: 'error', data: 'Invalid message format' }),
 | 
			
		||||
        JSON.stringify({
 | 
			
		||||
          type: 'error',
 | 
			
		||||
          data: 'Invalid message format',
 | 
			
		||||
          key: 'INVALID_FORMAT',
 | 
			
		||||
        }),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
    const history: BaseMessage[] = parsedMessage.history.map((msg) => {
 | 
			
		||||
@@ -99,11 +109,23 @@ export const handleMessage = async (
 | 
			
		||||
        );
 | 
			
		||||
        handleEmitterEvents(emitter, ws, id);
 | 
			
		||||
      } else {
 | 
			
		||||
        ws.send(JSON.stringify({ type: 'error', data: 'Invalid focus mode' }));
 | 
			
		||||
        ws.send(
 | 
			
		||||
          JSON.stringify({
 | 
			
		||||
            type: 'error',
 | 
			
		||||
            data: 'Invalid focus mode',
 | 
			
		||||
            key: 'INVALID_FOCUS_MODE',
 | 
			
		||||
          }),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    ws.send(JSON.stringify({ type: 'error', data: 'Invalid message format' }));
 | 
			
		||||
    ws.send(
 | 
			
		||||
      JSON.stringify({
 | 
			
		||||
        type: 'error',
 | 
			
		||||
        data: 'Invalid message format',
 | 
			
		||||
        key: 'INVALID_FORMAT',
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
    logger.error(`Failed to handle message: ${err}`);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user