dkress59 / wordpress-api-client

WordPress-API Client for JS/TS
https://dkress59.github.io/wordpress-api-client/
MIT License
18 stars 5 forks source link

error.json is nota function #15

Open devadee opened 1 year ago

devadee commented 1 year ago

I am trying to create an API in Typescript using the plugin. but i am getting the error :

TypeError: error.json is not a function
    at getErrorMessage (D:\personal\projects\blogger\node_modules\wordpress-api-client\dist\util.js:35:30)
    at FetchClient.fetch (D:\personal\projects\blogger\node_modules\wordpress-api-client\dist\fetch-client.js:54:62)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at FetchClient.post (D:\personal\projects\blogger\node_modules\wordpress-api-client\dist\fetch-client.js:90:17)
    at NewsService.blogHandler (D:\personal\projects\blogger\src\news\news.service.ts:35:22)
    at NewsController.getNews (D:\personal\projects\blogger\src\news\news.controller.ts:10:22)
    at D:\personal\projects\blogger\node_modules\@nestjs\core\router\router-execution-context.js:46:28
    at D:\personal\projects\blogger\node_modules\@nestjs\core\router\router-proxy.js:9:17
The code :

```

const wp = new WpApiClient('https://xxxxxxx.com/wp-json', {
  auth: {
    type: 'basic',
    password: '8FI9 8Uxqd ODB2 szDO JqaI YrPN',
    username: 'user',
  },
});
const posts = {
  date_gmt: '2022-01-01T12:34:56',
  date: '2022-01-01T12:34:56',
  guid: {
    raw: 'ttest',
    rendered: 'ttest',
  },
  link: 'https://xxxxx.com/ttest.php',
  modified: '2022-01-01T12:34:56',
  modified_gmt: '2022-01-01T12:34:56',
  type: 'post',
  slug: 'testt',
  title: {
    raw: '<h2>test title</h2>',
    rendered: 'Test Ttitle',
  },
  content: {
    protected: false,
    raw: '<h2>Bpdy test</h2>',
    rendered: 'Bpdy test',
  },
  status: 'publish',
  author: 1,
};
return wp
  .post()
  .create(posts)
  .then(function (response) {
    console.log(response);
    return response;
  })
  .catch((err) => {
    console.log(err);
  });
```