Selaa lähdekoodia

fix: Better handling when channel is not found

Michael Bromley 7 vuotta sitten
vanhempi
sitoutus
c218594953

+ 4 - 0
admin-ui/src/app/data/providers/interceptor.ts

@@ -81,6 +81,10 @@ export class DefaultInterceptor implements HttpInterceptor {
                             },
                         });
                     });
+                } else if (firstCode === 'CHANNEL_NOT_FOUND') {
+                    const message = graqhQLErrors.map(err => err.message).join('\n');
+                    this.displayErrorNotification(message);
+                    this.localStorageService.remove('activeChannelToken');
                 } else {
                     const message = graqhQLErrors.map(err => err.message).join('\n');
                     this.displayErrorNotification(message);

+ 12 - 12
server/dev-config.ts

@@ -24,23 +24,23 @@ export const devConfig: VendureConfig = {
         synchronize: false,
         logging: true,
 
-        // type: 'mysql',
-        // host: '192.168.99.100',
-        // port: 3306,
-        // username: 'root',
-        // password: '',
-        // database: 'vendure-dev',
+        type: 'mysql',
+        host: '192.168.99.100',
+        port: 3306,
+        username: 'root',
+        password: '',
+        database: 'vendure-dev',
 
         // type: 'sqljs',
         // database: new Uint8Array([]),
         // location:  path.join(__dirname, 'vendure.sqlite'),
 
-        type: 'postgres',
-        host: '127.0.0.1',
-        port: 5432,
-        username: 'postgres',
-        password: 'Be70',
-        database: 'vendure',
+        // type: 'postgres',
+        // host: '127.0.0.1',
+        // port: 5432,
+        // username: 'postgres',
+        // password: 'Be70',
+        // database: 'vendure',
     },
     orderProcessOptions: {} as OrderProcessOptions<any>,
     paymentOptions: {

+ 0 - 1
server/src/api/common/request-context.service.ts

@@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
 import { Request } from 'express';
 
 import { LanguageCode, Permission } from '../../../../shared/generated-types';
-import { NoValidChannelError } from '../../common/error/errors';
 import { idsAreEqual } from '../../common/utils';
 import { ConfigService } from '../../config/config.service';
 import { Channel } from '../../entity/channel/channel.entity';

+ 6 - 0
server/src/common/error/errors.ts

@@ -39,6 +39,12 @@ export class NoValidChannelError extends I18nError {
     }
 }
 
+export class ChannelNotFoundError extends I18nError {
+    constructor(token: string) {
+        super('error.channel-not-found', { token }, 'CHANNEL_NOT_FOUND');
+    }
+}
+
 export class EntityNotFoundError extends I18nError {
     constructor(entityName: keyof typeof coreEntitiesMap, id: ID) {
         super('error.entity-with-id-not-found', { entityName, id }, 'ENTITY_NOT_FOUND');

+ 2 - 2
server/src/service/services/channel.service.ts

@@ -8,7 +8,7 @@ import { ID } from '../../../../shared/shared-types';
 import { unique } from '../../../../shared/unique';
 import { RequestContext } from '../../api/common/request-context';
 import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
-import { EntityNotFoundError, InternalServerError } from '../../common/error/errors';
+import { ChannelNotFoundError, EntityNotFoundError, InternalServerError } from '../../common/error/errors';
 import { ChannelAware } from '../../common/types/common-types';
 import { assertFound } from '../../common/utils';
 import { ConfigService } from '../../config/config.service';
@@ -52,7 +52,7 @@ export class ChannelService {
         }
         const channel = this.allChannels.find(c => c.token === token);
         if (!channel) {
-            throw new InternalServerError(`error.channel-not-found`, { token });
+            throw new ChannelNotFoundError(token);
         }
         return channel;
     }