@superblocksteam/shared 0.9428.0 → 0.9430.0
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.
- package/dist/utils/response-dto.d.ts.map +1 -1
- package/dist/utils/response-dto.js +12 -1
- package/dist/utils/response-dto.js.map +1 -1
- package/dist-esm/utils/response-dto.d.ts.map +1 -1
- package/dist-esm/utils/response-dto.js +12 -1
- package/dist-esm/utils/response-dto.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/response-dto.ts +11 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-dto.d.ts","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response-dto.d.ts","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,WAAW,CAAC,CAAC,IAAI;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAevF"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unwrapResponseDto = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
4
5
|
async function unwrapResponseDto(request) {
|
|
5
6
|
const response = await request;
|
|
6
7
|
if (!response.responseMeta.success || response.responseMeta.error || response.responseMeta.status !== 200) {
|
|
7
|
-
|
|
8
|
+
const errorMessage = response.responseMeta.error?.message ?? response.responseMeta.message ?? `Request failed with status ${response.responseMeta.status}`;
|
|
9
|
+
if (response.responseMeta.status === 409) {
|
|
10
|
+
throw new errors_1.ConflictError(errorMessage);
|
|
11
|
+
}
|
|
12
|
+
else if (response.responseMeta.status === 404) {
|
|
13
|
+
throw new errors_1.NotFoundError(errorMessage);
|
|
14
|
+
}
|
|
15
|
+
else if (response.responseMeta.status === 400) {
|
|
16
|
+
throw new errors_1.BadRequestError(errorMessage);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(errorMessage);
|
|
8
19
|
}
|
|
9
20
|
return response.data;
|
|
10
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-dto.js","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"response-dto.js","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":";;;AAAA,sCAA0E;AAQnE,KAAK,UAAU,iBAAiB,CAAI,OAAgC;IACzE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC;IAC/B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;QACzG,MAAM,YAAY,GAChB,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,OAAO,IAAI,8BAA8B,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACxI,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YACxC,MAAM,IAAI,sBAAa,CAAC,YAAY,CAAC,CAAC;SACvC;aAAM,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YAC/C,MAAM,IAAI,sBAAa,CAAC,YAAY,CAAC,CAAC;SACvC;aAAM,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YAC/C,MAAM,IAAI,wBAAe,CAAC,YAAY,CAAC,CAAC;SACzC;QACD,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/B;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAfD,8CAeC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-dto.d.ts","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response-dto.d.ts","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,WAAW,CAAC,CAAC,IAAI;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAevF"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { BadRequestError, ConflictError, NotFoundError } from '../errors';
|
|
1
2
|
export async function unwrapResponseDto(request) {
|
|
2
3
|
const response = await request;
|
|
3
4
|
if (!response.responseMeta.success || response.responseMeta.error || response.responseMeta.status !== 200) {
|
|
4
|
-
|
|
5
|
+
const errorMessage = response.responseMeta.error?.message ?? response.responseMeta.message ?? `Request failed with status ${response.responseMeta.status}`;
|
|
6
|
+
if (response.responseMeta.status === 409) {
|
|
7
|
+
throw new ConflictError(errorMessage);
|
|
8
|
+
}
|
|
9
|
+
else if (response.responseMeta.status === 404) {
|
|
10
|
+
throw new NotFoundError(errorMessage);
|
|
11
|
+
}
|
|
12
|
+
else if (response.responseMeta.status === 400) {
|
|
13
|
+
throw new BadRequestError(errorMessage);
|
|
14
|
+
}
|
|
15
|
+
throw new Error(errorMessage);
|
|
5
16
|
}
|
|
6
17
|
return response.data;
|
|
7
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-dto.js","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response-dto.js","sourceRoot":"","sources":["../../src/utils/response-dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAQ1E,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAI,OAAgC;IACzE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC;IAC/B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;QACzG,MAAM,YAAY,GAChB,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,OAAO,IAAI,8BAA8B,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACxI,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YACxC,MAAM,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;SACvC;aAAM,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YAC/C,MAAM,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;SACvC;aAAM,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;YAC/C,MAAM,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC;SACzC;QACD,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/B;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BadRequestError, ConflictError, NotFoundError } from '../errors';
|
|
1
2
|
import { ResponseMeta } from '../types';
|
|
2
3
|
|
|
3
4
|
type ResponseDto<T> = {
|
|
@@ -8,9 +9,16 @@ type ResponseDto<T> = {
|
|
|
8
9
|
export async function unwrapResponseDto<T>(request: Promise<ResponseDto<T>>): Promise<T> {
|
|
9
10
|
const response = await request;
|
|
10
11
|
if (!response.responseMeta.success || response.responseMeta.error || response.responseMeta.status !== 200) {
|
|
11
|
-
|
|
12
|
-
response.responseMeta.error?.message ?? response.responseMeta.message ?? `Request failed with status ${response.responseMeta.status}
|
|
13
|
-
)
|
|
12
|
+
const errorMessage =
|
|
13
|
+
response.responseMeta.error?.message ?? response.responseMeta.message ?? `Request failed with status ${response.responseMeta.status}`;
|
|
14
|
+
if (response.responseMeta.status === 409) {
|
|
15
|
+
throw new ConflictError(errorMessage);
|
|
16
|
+
} else if (response.responseMeta.status === 404) {
|
|
17
|
+
throw new NotFoundError(errorMessage);
|
|
18
|
+
} else if (response.responseMeta.status === 400) {
|
|
19
|
+
throw new BadRequestError(errorMessage);
|
|
20
|
+
}
|
|
21
|
+
throw new Error(errorMessage);
|
|
14
22
|
}
|
|
15
23
|
return response.data;
|
|
16
24
|
}
|