Skip to content

Commit

Permalink
Merge pull request #4 from BrewInteractive/feature/error-management
Browse files Browse the repository at this point in the history
Feature/error classes
  • Loading branch information
mfozmen authored May 24, 2024
2 parents 2a07191 + 2ea1b37 commit c54ba6d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './missing-admin-secret.error';
5 changes: 5 additions & 0 deletions src/error/missing-admin-secret.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class MissingAdminSecret extends Error {
constructor() {
super('Missing admin secret.');
}
}
3 changes: 2 additions & 1 deletion src/hasura.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Test, TestingModule } from '@nestjs/testing';

import { HasuraConfigFixture } from '../test/fixtures';
import { HasuraService } from './hasura.service';
import { MissingAdminSecret } from './error';
import { gql } from 'graphql-request';

const graphqlClientSpy = jest.fn();
Expand Down Expand Up @@ -152,6 +153,6 @@ describe('HasuraService', () => {
query,
requestFlags,
});
}).rejects.toThrow(Error);
}).rejects.toThrow(MissingAdminSecret);
});
});
3 changes: 2 additions & 1 deletion src/hasura.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { GraphQLClient, Variables } from 'graphql-request';

import { Injectable } from '@nestjs/common';
import { MissingAdminSecret } from './error';

@Injectable()
export class HasuraService {
Expand Down Expand Up @@ -40,7 +41,7 @@ export class HasuraService {
private getAdminSecret(): string {
if (this.adminSecret) return this.adminSecret;

throw new Error('Missing admin secret.');
throw new MissingAdminSecret();
}

private createHeadersByRunQueryFlags(flags: RequestFlags) {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './hasura.module';
export * from './hasura.service';
export * from './models';
export * from './error';

0 comments on commit c54ba6d

Please sign in to comment.