Skip to content

Commit

Permalink
fix: catch and log exceptions on token validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus-Aguilar committed Jun 25, 2024
1 parent 83da76e commit 0d665c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
37 changes: 16 additions & 21 deletions node/resolvers/Queries/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,24 @@ export const isUserPartOfBuyerOrg = async (email: string, ctx: Context) => {
clients: { masterdata },
} = ctx

try {
const where = `email=${email}`
const resp = await masterdata.searchDocumentsWithPaginationInfo({
dataEntity: config.name,
fields: ['id'], // we don't need to fetch all fields, only if there is an entry or not
pagination: {
page: 1,
pageSize: 1, // we only need to know if there is at least one user entry
},
schema: config.version,
...(where ? { where } : {}),
})
const where = `email=${email}`
const resp = await masterdata.searchDocumentsWithPaginationInfo({
dataEntity: config.name,
fields: ['id'], // we don't need to fetch all fields, only if there is an entry or not
pagination: {
page: 1,
pageSize: 1, // we only need to know if there is at least one user entry
},
schema: config.version,
...(where ? { where } : {}),
})

const { data } = resp as unknown as {
data: any
}
const { data } = resp as unknown as {
data: any
}

if (data.length > 0) {
return true
}
} catch (error) {
// if it fails at somepoint, we treat it like no user was found
// on any buyer org, so we just let the function return false
if (data.length > 0) {
return true
}

return false
Expand Down
10 changes: 4 additions & 6 deletions node/utils/LicenseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ export class LMClient extends ExternalClient {
}

public getUserAdminPermissions = async (account: string, userId: string) => {
return this.get(this.routes.getUserAdminPermissions(account, userId))
.then((res: any) => {
return this.get(this.routes.getUserAdminPermissions(account, userId)).then(
(res: any) => {
return res
})
.catch(() => {
return false
})
}
)
}

protected get = <T>(url: string) => {
Expand Down

0 comments on commit 0d665c5

Please sign in to comment.