@arkyn/server 1.3.13 → 1.3.15
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/helpers/globalErrorHandler.d.ts +1 -1
- package/dist/helpers/globalErrorHandler.d.ts.map +1 -1
- package/dist/helpers/globalErrorHandler.js +3 -0
- package/dist/httpBadResponses/unprocessableEntity.d.ts +16 -0
- package/dist/httpBadResponses/unprocessableEntity.d.ts.map +1 -0
- package/dist/httpBadResponses/unprocessableEntity.js +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/helpers/globalErrorHandler.ts +6 -0
- package/src/httpBadResponses/unprocessableEntity.ts +38 -0
- package/src/index.ts +1 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const globalErrorHandler: (error: any) => import("@remix-run/node").TypedResponse<import("@arkyn/types").HttpResponse>;
|
|
1
|
+
declare const globalErrorHandler: (error: any) => import("@remix-run/node").TypedResponse<import("@arkyn/types").HttpResponse> | import("@remix-run/node").TypedResponse<import("@arkyn/types").HttpDataResponse>;
|
|
2
2
|
export { globalErrorHandler };
|
|
3
3
|
//# sourceMappingURL=globalErrorHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalErrorHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/globalErrorHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globalErrorHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/globalErrorHandler.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAM,kBAAkB,UAAW,GAAG,oKAuBrC,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { conflict, ConflictError } from "../httpBadResponses/conflict";
|
|
|
4
4
|
import { forbidden, ForbiddenError } from "../httpBadResponses/forbidden";
|
|
5
5
|
import { notFound, NotFoundError } from "../httpBadResponses/notFound";
|
|
6
6
|
import { serverError } from "../httpBadResponses/serverError";
|
|
7
|
+
import { UnprocessableEntityError, unprocessableEntity, } from "../httpBadResponses/unprocessableEntity";
|
|
7
8
|
import { unauthorized, UnauthorizedError, } from "../httpBadResponses/unauthorized";
|
|
8
9
|
const globalErrorHandler = (error) => {
|
|
9
10
|
switch (true) {
|
|
@@ -17,6 +18,8 @@ const globalErrorHandler = (error) => {
|
|
|
17
18
|
return json(unauthorized(error));
|
|
18
19
|
case error instanceof NotFoundError:
|
|
19
20
|
return json(notFound(error));
|
|
21
|
+
case error instanceof UnprocessableEntityError:
|
|
22
|
+
return json(unprocessableEntity(error));
|
|
20
23
|
default:
|
|
21
24
|
return json(serverError({
|
|
22
25
|
message: error?.message || "Server error | Message not found",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpDataResponse } from "@arkyn/types";
|
|
2
|
+
type UnprocessableEntityErrorProps = {
|
|
3
|
+
data?: any;
|
|
4
|
+
fieldErrors?: Record<string, string>;
|
|
5
|
+
fields?: Record<string, string>;
|
|
6
|
+
message?: string;
|
|
7
|
+
};
|
|
8
|
+
declare function unprocessableEntity(error: UnprocessableEntityError): HttpDataResponse;
|
|
9
|
+
declare class UnprocessableEntityError extends Error {
|
|
10
|
+
fieldErrors: any;
|
|
11
|
+
fields: any;
|
|
12
|
+
data: any;
|
|
13
|
+
constructor(data: UnprocessableEntityErrorProps);
|
|
14
|
+
}
|
|
15
|
+
export { unprocessableEntity, UnprocessableEntityError };
|
|
16
|
+
//# sourceMappingURL=unprocessableEntity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,KAAK,6BAA6B,GAAG;IACnC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,iBAAS,mBAAmB,CAC1B,KAAK,EAAE,wBAAwB,GAC9B,gBAAgB,CAUlB;AAED,cAAM,wBAAyB,SAAQ,KAAK;IAC1C,WAAW,EAAE,GAAG,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;gBAEE,IAAI,EAAE,6BAA6B;CAOhD;AAED,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function unprocessableEntity(error) {
|
|
2
|
+
return {
|
|
3
|
+
status: 400,
|
|
4
|
+
success: false,
|
|
5
|
+
name: error.name,
|
|
6
|
+
message: error.message,
|
|
7
|
+
data: error.data || null,
|
|
8
|
+
fieldErrors: error.fieldErrors || null,
|
|
9
|
+
fields: error.fields || null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
class UnprocessableEntityError extends Error {
|
|
13
|
+
fieldErrors;
|
|
14
|
+
fields;
|
|
15
|
+
data;
|
|
16
|
+
constructor(data) {
|
|
17
|
+
super(data.message);
|
|
18
|
+
this.data = data?.data || null;
|
|
19
|
+
this.fieldErrors = data?.fieldErrors || null;
|
|
20
|
+
this.fields = data?.fields || null;
|
|
21
|
+
this.name = "UnprocessableEntityError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export { unprocessableEntity, UnprocessableEntityError };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { ForbiddenError } from "./httpBadResponses/forbidden";
|
|
|
4
4
|
export { NotFoundError } from "./httpBadResponses/notFound";
|
|
5
5
|
export { ServerError } from "./httpBadResponses/serverError";
|
|
6
6
|
export { UnauthorizedError } from "./httpBadResponses/unauthorized";
|
|
7
|
+
export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity";
|
|
7
8
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|
|
8
9
|
export { formParse } from "./helpers/formParse";
|
|
9
10
|
export { getScopedParams } from "./helpers/getScopedParams";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { ForbiddenError } from "./httpBadResponses/forbidden";
|
|
|
5
5
|
export { NotFoundError } from "./httpBadResponses/notFound";
|
|
6
6
|
export { ServerError } from "./httpBadResponses/serverError";
|
|
7
7
|
export { UnauthorizedError } from "./httpBadResponses/unauthorized";
|
|
8
|
+
export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity";
|
|
8
9
|
// helpers
|
|
9
10
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|
|
10
11
|
export { formParse } from "./helpers/formParse";
|
package/package.json
CHANGED
|
@@ -5,6 +5,10 @@ import { conflict, ConflictError } from "../httpBadResponses/conflict";
|
|
|
5
5
|
import { forbidden, ForbiddenError } from "../httpBadResponses/forbidden";
|
|
6
6
|
import { notFound, NotFoundError } from "../httpBadResponses/notFound";
|
|
7
7
|
import { serverError } from "../httpBadResponses/serverError";
|
|
8
|
+
import {
|
|
9
|
+
UnprocessableEntityError,
|
|
10
|
+
unprocessableEntity,
|
|
11
|
+
} from "../httpBadResponses/unprocessableEntity";
|
|
8
12
|
import {
|
|
9
13
|
unauthorized,
|
|
10
14
|
UnauthorizedError,
|
|
@@ -22,6 +26,8 @@ const globalErrorHandler = (error: any) => {
|
|
|
22
26
|
return json(unauthorized(error));
|
|
23
27
|
case error instanceof NotFoundError:
|
|
24
28
|
return json(notFound(error));
|
|
29
|
+
case error instanceof UnprocessableEntityError:
|
|
30
|
+
return json(unprocessableEntity(error));
|
|
25
31
|
default:
|
|
26
32
|
return json(
|
|
27
33
|
serverError({
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HttpDataResponse } from "@arkyn/types";
|
|
2
|
+
|
|
3
|
+
type UnprocessableEntityErrorProps = {
|
|
4
|
+
data?: any;
|
|
5
|
+
fieldErrors?: Record<string, string>;
|
|
6
|
+
fields?: Record<string, string>;
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function unprocessableEntity(
|
|
11
|
+
error: UnprocessableEntityError
|
|
12
|
+
): HttpDataResponse {
|
|
13
|
+
return {
|
|
14
|
+
status: 400,
|
|
15
|
+
success: false,
|
|
16
|
+
name: error.name,
|
|
17
|
+
message: error.message,
|
|
18
|
+
data: error.data || null,
|
|
19
|
+
fieldErrors: error.fieldErrors || null,
|
|
20
|
+
fields: error.fields || null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class UnprocessableEntityError extends Error {
|
|
25
|
+
fieldErrors: any;
|
|
26
|
+
fields: any;
|
|
27
|
+
data: any;
|
|
28
|
+
|
|
29
|
+
constructor(data: UnprocessableEntityErrorProps) {
|
|
30
|
+
super(data.message);
|
|
31
|
+
this.data = data?.data || null;
|
|
32
|
+
this.fieldErrors = data?.fieldErrors || null;
|
|
33
|
+
this.fields = data?.fields || null;
|
|
34
|
+
this.name = "UnprocessableEntityError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { unprocessableEntity, UnprocessableEntityError };
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { ForbiddenError } from "./httpBadResponses/forbidden";
|
|
|
5
5
|
export { NotFoundError } from "./httpBadResponses/notFound";
|
|
6
6
|
export { ServerError } from "./httpBadResponses/serverError";
|
|
7
7
|
export { UnauthorizedError } from "./httpBadResponses/unauthorized";
|
|
8
|
+
export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity";
|
|
8
9
|
|
|
9
10
|
// helpers
|
|
10
11
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|