Hey there!
I’m building a tool around Uploadcare, where users will be required to use their pubkeys to upload images to Uploadcare. I’d like to validate their pubkeys prior to letting them use the tool. Just to make UX a bit better.
Which way should I use? Is there any pubkey validation method? Currently I found only this solution:
const { info } = require('@uploadcare/upload-client');
(async () => {
console.log(await isPublicKeyInvalid('invalid key'));
console.log(await isPublicKeyInvalid('demopublickey'));
})();
async function isPublicKeyInvalid(publicKey) {
try {
await info(
'nothing here',
{
publicKey,
}
);
} catch (err) {
const apiError = err.response.error;
return apiError.statusCode === 403 && apiError.errorCode === 'ProjectPublicKeyInvalidError';
}
}
$ node index.js
true
false
Is there a way to make it more bulletproof? May I rely on errorCode
there?