@er3tickets/common 0.0.12 → 0.0.13

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.
@@ -0,0 +1,4 @@
1
+ import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ export declare class GraphqlExceptionFilter implements ExceptionFilter {
3
+ catch(exception: unknown, host: ArgumentsHost): void;
4
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.GraphqlExceptionFilter = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const graphql_1 = require("graphql");
12
+ const custom_error_1 = require("../errors/custom-error");
13
+ let GraphqlExceptionFilter = class GraphqlExceptionFilter {
14
+ catch(exception, host) {
15
+ if (exception instanceof custom_error_1.CustomError) {
16
+ throw new graphql_1.GraphQLError(exception.message, {
17
+ extensions: {
18
+ code: exception.statusCode,
19
+ errors: exception.serializeErrors(),
20
+ },
21
+ });
22
+ }
23
+ if (exception instanceof common_1.HttpException) {
24
+ const status = exception.getStatus();
25
+ const response = exception.getResponse();
26
+ const errors = typeof response === 'object'
27
+ ? response.errors ?? [{ message: exception.message }]
28
+ : [{ message: response }];
29
+ throw new graphql_1.GraphQLError(exception.message, {
30
+ extensions: {
31
+ code: status,
32
+ errors,
33
+ },
34
+ });
35
+ }
36
+ console.error(exception);
37
+ throw new graphql_1.GraphQLError('Something went wrong', {
38
+ extensions: {
39
+ code: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
40
+ errors: [{ message: 'Internal server error' }],
41
+ },
42
+ });
43
+ }
44
+ };
45
+ exports.GraphqlExceptionFilter = GraphqlExceptionFilter;
46
+ exports.GraphqlExceptionFilter = GraphqlExceptionFilter = __decorate([
47
+ (0, common_1.Catch)()
48
+ ], GraphqlExceptionFilter);
49
+ //# sourceMappingURL=custom-graphql-exception.filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-graphql-exception.filter.js","sourceRoot":"","sources":["../../src/filters/custom-graphql-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAMwB;AACxB,qCAAuC;AACvC,yDAAqD;AAG9C,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,KAAK,CAAC,SAAkB,EAAE,IAAmB;QAE3C,IAAI,SAAS,YAAY,0BAAW,EAAE,CAAC;YACrC,MAAM,IAAI,sBAAY,CAAC,SAAS,CAAC,OAAO,EAAE;gBACxC,UAAU,EAAE;oBACV,IAAI,EAAE,SAAS,CAAC,UAAU;oBAC1B,MAAM,EAAE,SAAS,CAAC,eAAe,EAAE;iBACpC;aACF,CAAC,CAAC;QACL,CAAC;QAGD,IAAI,SAAS,YAAY,sBAAa,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;YAEzC,MAAM,MAAM,GACV,OAAO,QAAQ,KAAK,QAAQ;gBAC1B,CAAC,CAAE,QAAgB,CAAC,MAAM,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC;gBAC9D,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;YAE9B,MAAM,IAAI,sBAAY,CAAC,SAAS,CAAC,OAAO,EAAE;gBACxC,UAAU,EAAE;oBACV,IAAI,EAAE,MAAM;oBACZ,MAAM;i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