@akanjs/nest 1.0.14 → 1.0.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.
@@ -31,28 +31,42 @@ __export(exceptions_exports, {
31
31
  module.exports = __toCommonJS(exceptions_exports);
32
32
  var import_common = require("@akanjs/common");
33
33
  var import_common2 = require("@nestjs/common");
34
+ var import_graphql = require("graphql");
34
35
  let AllExceptionsFilter = class {
35
36
  logger = new import_common.Logger("Exception Filter");
37
+ getStatus(exception) {
38
+ return exception instanceof import_common2.HttpException ? exception.getStatus() : import_common2.HttpStatus.INTERNAL_SERVER_ERROR;
39
+ }
36
40
  catch(exception, host) {
37
41
  if (host.getType() !== "http") {
38
42
  const gqlArgs = host.getArgByIndex(1);
39
43
  const gqlReq = host.getArgByIndex(3);
40
44
  const reqType2 = gqlReq?.parentType?.name ?? "unknown";
41
45
  const reqName2 = gqlReq?.fieldName ?? "unknown";
46
+ const status2 = this.getStatus(exception);
47
+ const extensions = exception instanceof import_graphql.GraphQLError ? exception.extensions : {};
48
+ const httpExtension = typeof extensions.http === "object" && extensions.http !== null ? extensions.http : {};
42
49
  this.logger.error(
43
50
  `GraphQL Error
44
51
  Request: ${reqType2}-${reqName2}
45
52
  Args: ${JSON.stringify(gqlArgs, null, 2)}
46
53
  ${exception.stack}`
47
54
  );
48
- throw exception;
55
+ throw new import_graphql.GraphQLError(exception.message, {
56
+ originalError: exception,
57
+ extensions: {
58
+ ...extensions,
59
+ statusCode: status2,
60
+ http: { ...httpExtension, status: status2 }
61
+ }
62
+ });
49
63
  }
50
64
  const ctx = host.switchToHttp();
51
65
  const res = ctx.getResponse();
52
66
  const req = ctx.getRequest();
53
67
  const reqType = req.method;
54
68
  const reqName = req.url;
55
- const status = exception instanceof import_common2.HttpException ? exception.getStatus() : import_common2.HttpStatus.INTERNAL_SERVER_ERROR;
69
+ const status = this.getStatus(exception);
56
70
  res.status(status).json({
57
71
  statusCode: status,
58
72
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -11,28 +11,42 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
  import { Logger } from "@akanjs/common";
13
13
  import { Catch, HttpException, HttpStatus } from "@nestjs/common";
14
+ import { GraphQLError } from "graphql";
14
15
  let AllExceptionsFilter = class {
15
16
  logger = new Logger("Exception Filter");
17
+ getStatus(exception) {
18
+ return exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;
19
+ }
16
20
  catch(exception, host) {
17
21
  if (host.getType() !== "http") {
18
22
  const gqlArgs = host.getArgByIndex(1);
19
23
  const gqlReq = host.getArgByIndex(3);
20
24
  const reqType2 = gqlReq?.parentType?.name ?? "unknown";
21
25
  const reqName2 = gqlReq?.fieldName ?? "unknown";
26
+ const status2 = this.getStatus(exception);
27
+ const extensions = exception instanceof GraphQLError ? exception.extensions : {};
28
+ const httpExtension = typeof extensions.http === "object" && extensions.http !== null ? extensions.http : {};
22
29
  this.logger.error(
23
30
  `GraphQL Error
24
31
  Request: ${reqType2}-${reqName2}
25
32
  Args: ${JSON.stringify(gqlArgs, null, 2)}
26
33
  ${exception.stack}`
27
34
  );
28
- throw exception;
35
+ throw new GraphQLError(exception.message, {
36
+ originalError: exception,
37
+ extensions: {
38
+ ...extensions,
39
+ statusCode: status2,
40
+ http: { ...httpExtension, status: status2 }
41
+ }
42
+ });
29
43
  }
30
44
  const ctx = host.switchToHttp();
31
45
  const res = ctx.getResponse();
32
46
  const req = ctx.getRequest();
33
47
  const reqType = req.method;
34
48
  const reqName = req.url;
35
- const status = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;
49
+ const status = this.getStatus(exception);
36
50
  res.status(status).json({
37
51
  statusCode: status,
38
52
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/nest",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,6 +26,7 @@
26
26
  "@nestjs/schedule": "^4.1.2",
27
27
  "@socket.io/redis-adapter": "^8.3.0",
28
28
  "apple-signin": "^1.0.9",
29
+ "graphql": "^16.10.0",
29
30
  "iap": "^1.1.1",
30
31
  "jsonwebtoken": "^9.0.2",
31
32
  "mongoose": "^8.9.3",
@@ -1,5 +1,6 @@
1
1
  import { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
2
2
  export declare class AllExceptionsFilter implements ExceptionFilter {
3
3
  private readonly logger;
4
+ private getStatus;
4
5
  catch(exception: Error, host: ArgumentsHost): void;
5
6
  }