Skip to content

Commit

Permalink
Add an insufficient-permissions error code for similarCards.
Browse files Browse the repository at this point in the history
Part of #646.
  • Loading branch information
jkomoros committed Nov 14, 2023
1 parent 7e51902 commit 79fa356
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion functions/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,15 @@ export const similarCards = async (request : CallableRequest<SimilarCardsRequest

if (data.card) {
//We will hit the openai endpoint, so verify we're allowed.
await throwIfUserMayNotUseAI(request);
try {
await throwIfUserMayNotUseAI(request);
} catch(err) {
return {
success: false,
code: 'insufficient-permissions',
error: String(err)
};
}

if (data.card.id != data.card_id) throw new Error(`Card.id was ${data.card.id} which did not match card_id: ${data.card_id}`);

Expand Down
2 changes: 1 addition & 1 deletion functions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export type CardSimilarityItem = [CardID, number];
//Replicated in `src/actions/similarity.ts`
export type SimilarCardsResponseData = {
success: false,
code: 'qdrant-disabled' | 'no-embedding' | 'stale-embedding' | 'unknown'
code: 'qdrant-disabled' | 'insufficient-permissions' | 'no-embedding' | 'stale-embedding' | 'unknown'
error: string
} | {
success: true
Expand Down
2 changes: 1 addition & 1 deletion src/actions/similarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type CardSimilarityItem = [CardID, number];
//Replicated in `functions/src/types.ts`
type SimilarCardsResponseData = {
success: false,
code: 'qdrant-disabled' | 'no-embedding' | 'stale-embedding' | 'unknown'
code: 'qdrant-disabled' | 'insufficient-permissions' | 'no-embedding' | 'stale-embedding' | 'unknown'
error: string
} | {
success: true
Expand Down

0 comments on commit 79fa356

Please sign in to comment.