Skip to content

Commit

Permalink
fix(data_layer): Throw error if Notion token is not found (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu authored Jul 14, 2023
1 parent 01298d7 commit 10518f0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/data_layer/NotionRespository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ class NotionRepository {
});
}

/**
* Retrieve the users notion token.
* If the user does not have a token, throws error.
* The caller is expected to handle this error.
*
* @param owner user id
* @returns unhashed token
*/
async getNotionToken(owner: string) {
if (!owner) {
return null;
}
const row = await this.database('notion_tokens')
.where({ owner })
.returning('token')
.first();

if (!row) {
throw new Error(
`Could not find your Notion token. Please report this issue with your userid: ${owner}`
);
}

return unHashToken(row.token);
}

Expand Down

0 comments on commit 10518f0

Please sign in to comment.