Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue importing 'FacebookRequestError' #270

Open
mrowles opened this issue Jan 11, 2024 · 3 comments
Open

Issue importing 'FacebookRequestError' #270

mrowles opened this issue Jan 11, 2024 · 3 comments

Comments

@mrowles
Copy link

mrowles commented Jan 11, 2024

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.

@kishanio
Copy link

kishanio commented Feb 7, 2024

This is needed for above usecase

@gregleongf
Copy link
Contributor

I'm currently doing

if (error.constructor.name === 'FacebookRequestError') {
    ...
}

But it would be great to import the class.

@mauudev
Copy link

mauudev commented Jul 2, 2024

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 :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants