facebook-nodejs-business-sdk
facebook-nodejs-business-sdk copied to clipboard
Issue importing 'FacebookRequestError'
Which SDK version are you using?
18.0.0
What's the issue?
Cannot import FacebookRequestError from facebook-nodejs-business-sdk/src/exceptions.d.ts (can import anything else which is exported from index.d.ts of course).
I would like to import this as to do:
} catch (error) {
if (error instanceof FacebookRequestError) {
throw new Error(`Something went wrong: [${error.response}]`);
}
throw new Error('Something went wrong');
}
I assume there is some convoluted way to import this safely without complaints, but would prefer this is just accessible so I can reference the class easily. If there is a smarter way to do this, all ears!
My workaround is:
} catch (error) {
if ('response' in error) {
throw new Error(`Something went wrong: [${error.response}]`);
}
throw new Error('Something went wrong');
}
Steps/Sample code to reproduce the issue
import {
Ad,
AdAccount,
Campaign,
FacebookAdsApi,
} from 'facebook-nodejs-business-sdk';
import FacebookExceptions from 'facebook-nodejs-business-sdk/src/exceptions'; // <-- it would be good if this was exposed through index.d.ts as this import does not work (see observed results)
Observed Results:
export class FacebookRequestError extends FacebookError {
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1288:20)
at Module._compile (node:internal/modules/cjs/loader:1340:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Object.require.extensions.<computed> [as .js] (/Users/user/workspace/some-repo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/Users/user/workspace/some-repo/packages/service/src/lib/facebook.ts:7:1)
Expected Results:
This was easily importable since it's exported from index.
This is needed for above usecase
I'm currently doing
if (error.constructor.name === 'FacebookRequestError') {
...
}
But it would be great to import the class.
Hello here, I'm facing the same issue and doing the same workaround .. did you were able to import any sdk exceptions? Since there is a lot code errors to handle, this is a must for any conversions API development. I'm concerned that it's still open :/