Skip to content

Commit

Permalink
protocol error
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilde345 committed Dec 13, 2024
1 parent 789a921 commit 587aa97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 4 additions & 3 deletions __tests__/unit/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AuthorizationError,
FetchClient,
fql,
ProtocolError,
QueryTimeoutError,
ServiceError,
ServiceInternalError,
Expand Down Expand Up @@ -123,7 +124,7 @@ describe("query", () => {
expect(actual.summary).toEqual("the summary");
});

it("Throws ServiceError on an empty 200 response", async () => {
it("Throws ProtocolError on an empty 200 response", async () => {
expect.assertions(2);
fetchMock.mockResponse("", {
status: 200,
Expand All @@ -133,9 +134,9 @@ describe("query", () => {
const result = await client.query(fql`'foo'.length`);
console.log("result", result);
} catch (e) {
if (e instanceof ServiceError) {
if (e instanceof ProtocolError) {
expect(e.message).toEqual(
"There was an issue communicating with Fauna. Please try again.",
"There was an issue communicating with Fauna. Response is empty. Please try again.",
);
expect(e.httpStatus).toEqual(500);
}
Expand Down
16 changes: 5 additions & 11 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
NetworkError,
ProtocolError,
ServiceError,
ServiceInternalError,
ThrottlingError,
getServiceError,
} from "./errors";
Expand Down Expand Up @@ -646,16 +645,11 @@ in an environmental variable named FAUNA_SECRET or pass it to the Client\
response.body.length === 0 &&
response.headers["content-length"] === "0"
) {
throw new ServiceInternalError(
{
error: {
code: "internal_error",
message:
"There was an issue communicating with Fauna. Please try again.",
},
},
500,
);
throw new ProtocolError({
message:
"There was an issue communicating with Fauna. Response is empty. Please try again.",
httpStatus: 500,
});
}

let parsedResponse;
Expand Down

0 comments on commit 587aa97

Please sign in to comment.