# An unexpected error occured

**URL:** <https://community.apollographql.com/t/an-unexpected-error-occured/7990>\
**Category:** Server\
**Tags:** server\
**Created:** [December 10, 2024, 3:21pm UTC](https://community.apollographql.com/t/an-unexpected-error-occured/7990 "2024-12-10T15:21:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sailesh](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/sailesh/32/5358_2.png) [@sailesh](https://community.apollographql.com/u/sailesh)\
**Post date:** [December 10, 2024, 3:21pm UTC](https://community.apollographql.com/t/an-unexpected-error-occured/7990/1 "2024-12-10T15:21:26Z")

</div>

Hii Everyone

I’m facing a few challenges while migrating from apollo server v3 to v4.

Specifically in RESTDataSource.

Even when following the same syntax, in one of subclasses of RESTDataSource, I’m able to get correct response.

In another subclass which follows exactly the same structure I’m getting an error in didEncounterError hook

```auto
{
 message: "An unexpected error occured",
requestid: "some_random_string_of_numbers"
}

```

While migrating I considered the new way of passing body and bearer token in the request.

If I’m using axios instead of this.post, I’m able to get the response from the same request body and auth token.

When debugged in apollo/restdatasource package I found the error is originating from this.parseBody function.

Has anyone faced a similar issue while migrating?

I’ve initiated a github issue thread for the same as well.

> <https://github.com/apollographql/datasource-rest/issues/377>
>
> While migrating from apollo-server v3 to v4 getting error while executing few gr…aphql queries, whereas it's working fine for other graphql queries
> 
> \`\`\`
> SOME\_GRAPHQL\_QUERY TypeError: The "list" argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView.
> at TextDecoder.decode (node:internal/encoding:443:16)
> at Qe.someApplicationFunction1 (path/build/server.js:1:130571)
> at Qe.didEncounterError (path/build/server.js:1:133550)
> at path/node\_modules/@apollo/datasource-rest/dist/RESTDataSource.js:236:26
> at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)
> at async Qe.fetch (path/node\_modules/@apollo/datasource-rest/dist/RESTDataSource.js:269:21)
> at async Qe.post (path/node\_modules/@apollo/datasource-rest/dist/RESTDataSource.js:127:17)
> at async Qe.t.timeout (path/build/server.js:1:135424) {
> code: 'ERR\_INVALID\_ARG\_TYPE'
> }
> \`\`\`
> 
> The \_\*\*error.extensions.response.body\*\*\_ received in didEncounterError is: 
> 
> \`\`\`
> {
> message: 'An unexpected error occurred',
> request\_id: '59ba9f0ad155044a5f9d983891ab9559'
> }
> \`\`\`
> 
> Upon analysing the issue from the error callstack, found that the error is originating from \`\`\`const parsedBody = await this.parseBody(response);\`\`\` inside performRequest method.
> 
> Inside parsedBody, these are values found in response:
> \`\`\`
> contentType: application/json; charset=utf-8
> contentLength: 97
> response.status: 500
> \`\`\`
> 
> As the graphql server working fine for other queries, I suspect there might be some issue in the schema of few queries for which it fails with the above error message. So I tried running the query by passing just one String type input but it still failed with same error.
> 
> Any assistance on this would be highly appreciated
> 
> Versions used:
> node: v20.17.0
> graphql: ^16.9.0
> @apollo/datasource-rest: ^6.3.0
> @apollo/server: ^4.11.2
> graphql-tag: ^2.12.6

I would appreciate you support and help 🙂
