@dotdev/harmony-sdk 1.32.0 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { ApiError, RequestError } from "../errors";
2
+ import { ApiError, HarmonyAPIError } from "../errors";
3
3
  import { ParamLimits, ServiceAlias } from "../modules";
4
4
  export * from "./utils";
5
5
  export declare abstract class ApiHelper {
@@ -26,7 +26,7 @@ export declare abstract class ApiHelper {
26
26
  * @returns {Promise<R>}
27
27
  */
28
28
  static sendServiceRequest<R>(serviceName: string, methodName: string | string[], sessionId: string, serviceAlias: ServiceAlias, axios: AxiosInstance, body?: string): Promise<R>;
29
- static parseError(error: any): Promise<RequestError>;
29
+ static parseError(error: any): Promise<HarmonyAPIError>;
30
30
  /**
31
31
  * Extract error response from Harmony in XML format and convert it to JSON format for ease of debugging
32
32
  *
@@ -1,7 +1,7 @@
1
1
  import axios from "axios";
2
2
  import { promisify } from "util";
3
3
  import { parseString } from "xml2js";
4
- import { RequestError } from "../errors";
4
+ import { HarmonyAPIError, RequestError } from "../errors";
5
5
  import { logger } from "./logger";
6
6
  import { Utils } from "./utils";
7
7
  export * from "./utils";
@@ -98,6 +98,16 @@ export class ApiHelper {
98
98
  return response[responseMethodName][0];
99
99
  }
100
100
  static async parseError(error) {
101
+ // An already-parsed Harmony error (re-thrown up through a module-level
102
+ // catch) must pass through unchanged. Re-parsing it would hit the
103
+ // non-axios fallthrough below and discard its status/code, masking the
104
+ // real fault (e.g. a 500 "Invalid Session") behind the generic
105
+ // "Unexpected error" message before it reaches the caller. The first
106
+ // parse already logged this fault, so we deliberately don't re-log it
107
+ // here. [DAT-2135]
108
+ if (error instanceof HarmonyAPIError) {
109
+ return error;
110
+ }
101
111
  if (axios.isAxiosError(error)) {
102
112
  const status = error?.response?.status;
103
113
  const childLogger = logger.child({
@@ -1,6 +1,6 @@
1
1
  import axios from "axios";
2
2
  import { ApiHelper, checkParamLimits, TEST_HEADERS, Utils } from ".";
3
- import { RequestError } from "../errors";
3
+ import { AuthenticationError, RequestError } from "../errors";
4
4
  import { ServiceAlias } from "../modules/shared/types";
5
5
  // Increase timeout due to Harmony API having long response time
6
6
  jest.setTimeout(999999);
@@ -235,6 +235,31 @@ describe("ApiHelper.parseError", () => {
235
235
  expect(result.status).toBeUndefined();
236
236
  expect(result.message).toBe("Unexpected error occurred during API request");
237
237
  });
238
+ it("returns an already-parsed HarmonyAPIError unchanged (no re-masking) [DAT-2135]", async () => {
239
+ // A module-level catch may re-parse an error that sendSoapRequest already
240
+ // turned into a RequestError carrying status/code. Re-parsing must NOT
241
+ // discard those — otherwise the real fault (e.g. a 500 "Invalid Session")
242
+ // is masked behind the generic "Unexpected error" message and never
243
+ // reaches the caller.
244
+ const alreadyParsed = new RequestError(`API request failed with status 500: {code: S:Server, name: Invalid Session., message: }`, { status: 500, code: "S:Server" });
245
+ const result = await ApiHelper.parseError(alreadyParsed);
246
+ expect(result).toBe(alreadyParsed);
247
+ expect(result.status).toBe(500);
248
+ expect(result.code).toBe("S:Server");
249
+ expect(result.message).toContain("Invalid Session.");
250
+ });
251
+ it("does not downgrade an already-parsed AuthenticationError [DAT-2135]", async () => {
252
+ // AuthenticationError is the other HarmonyAPIError subclass; a 401 session
253
+ // drop must keep its type and status, not be re-parsed into a RequestError.
254
+ const authErr = new AuthenticationError("Invalid Session.", {
255
+ status: 401,
256
+ code: "S:Server",
257
+ });
258
+ const result = await ApiHelper.parseError(authErr);
259
+ expect(result).toBe(authErr);
260
+ expect(result).toBeInstanceOf(AuthenticationError);
261
+ expect(result.status).toBe(401);
262
+ });
238
263
  it("preserves gift-card serial-number substring in message (backward-compat)", async () => {
239
264
  const err = makeAxiosError({
240
265
  response: { status: 400, data: GIFT_CARD_SERIAL_FAULT },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotdev/harmony-sdk",
3
- "version": "1.32.0",
3
+ "version": "1.32.1",
4
4
  "description": "Harmony API SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",