Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions app/(auth)/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export const getAllWorkspaces = async (
`Fetching workspaces failed with error code ${allWorkspacesResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while fetching workspaces',
),
);
}
};

Expand Down Expand Up @@ -76,7 +81,12 @@ export const createWorkspace = async (
}
return Err(`Creating workspace failed with error code ${response.status}`);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while creating workspace',
),
);
}
};

Expand Down Expand Up @@ -106,7 +116,12 @@ export const getAllProjects = async (
`Fetching projects failed with error code ${allProjectsResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while fetching projects',
),
);
}
};

Expand Down Expand Up @@ -140,6 +155,11 @@ export const createProjectInWorkspace = async (
}
return Err(`Creating project failed with error code ${response.status}`);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while creating project',
),
);
}
};
59 changes: 52 additions & 7 deletions app/(chat)/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const getConversation = async (
`Fetching conversation failed with error code ${conversationResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while fetching conversation',
),
);
}
};

Expand Down Expand Up @@ -91,7 +96,12 @@ export const getConversationMessages = async (
`Fetching conversation messages failed with error code ${conversationResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while fetching conversation messages',
),
);
}
};

Expand Down Expand Up @@ -138,7 +148,12 @@ export const createConversation = async (
`Creating conversation failed with error code ${conversationResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while creating conversation',
),
);
}
};

Expand Down Expand Up @@ -185,7 +200,12 @@ export const sendMessage = async (
`Sending message failed with error code ${messageResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while sending message',
),
);
}
};

Expand Down Expand Up @@ -228,11 +248,26 @@ export const sendMessageStreamed = async (
: Err('Message was sent but stream object is null');
}

/**
* This error is specifically handled because the user should know the
* reason, so that they can top up their MOR stake if needed
*/
if (messageResponse.status === 429) {
return Err(
'You have used all your daily prompt credits. Please top up your MOR stake to continue, or wait until tomorrow.',
);
}

return Err(
`Sending message failed with error code ${messageResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while sending streamed message',
),
);
}
};

Expand Down Expand Up @@ -267,7 +302,12 @@ export const getAllConversations = async (
`Fetching projects failed with error code ${allConversationsResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while fetching all conversations',
),
);
}
};

Expand Down Expand Up @@ -311,6 +351,11 @@ export const renameConversation = async (
`Renaming conversation failed with error code ${renameResponse.status}`,
);
} catch (error) {
return Err(extractErrorMessageOrDefault(error));
return Err(
extractErrorMessageOrDefault(
error,
'Unknown error while renaming conversation',
),
);
}
};
8 changes: 7 additions & 1 deletion app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ export async function POST(request: Request) {
});
},
onError: (error) => {
return extractErrorMessageOrDefault(error);
/**
* We may get an error object when calling message API, or an error string
* when transforming the stream
*/
return typeof error === 'string'
? error
: extractErrorMessageOrDefault(error);
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function Chat({
mutate('/api/history');
},
onError: (error) => {
toast.error('An error occured, please try again!');
toast.error(error.message);
},
});

Expand Down
7 changes: 1 addition & 6 deletions lib/ai/pattern-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import type {
ToolStartEvent,
} from '@/lib/ai/types';

import { extractErrorMessageOrDefault } from '../utils';

const textDecoder = new TextDecoder();

export class PatternModel implements LanguageModelV1 {
Expand Down Expand Up @@ -115,10 +113,7 @@ export class PatternModel implements LanguageModelV1 {
} catch (error) {
controller.enqueue({
type: 'error',
error: extractErrorMessageOrDefault(
error,
'An unknown error occurred when transforming response chunk',
),
error: 'Cannot parse chunk due to corrupted data or invalid JSON',
});
}
} else {
Expand Down