Ver código fonte

Specify error responses

Use error classes to specify the error codes and body.
master
TheoryOfNekomata 2 anos atrás
pai
commit
3ef32e6025
1 arquivos alterados com 7 adições e 2 exclusões
  1. +7
    -2
      src/modules/git/Git.service.ts

+ 7
- 2
src/modules/git/Git.service.ts Ver arquivo

@@ -1,10 +1,15 @@
import {constants} from 'http2';
import * as codeCore from '@modal/code-core';
import {HttpError} from '../../packages/fastify-compliant-http-errors';

export interface GitService {
createRepo(options: codeCore.git.CreateRepoData, user?: codeCore.common.User): Promise<codeCore.git.Repo>;
deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void>
}

export class UnableToCreateRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Create Repo') {}
export class UnableToDeleteRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Delete Repo') {}

export class GitServiceImpl implements GitService {
private readonly coreGitService: codeCore.git.GitService;

@@ -16,13 +21,13 @@ export class GitServiceImpl implements GitService {
if (user) {
return this.coreGitService.create(options, user);
}
throw new Error('Unauthorized');
throw new UnableToCreateRepoError('Unauthorized');
}

async deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> {
if (user) {
await this.coreGitService.delete(repoId, user);
}
throw new Error('Unauthorized');
throw new UnableToDeleteRepoError('Unauthorized');
}
}

Carregando…
Cancelar
Salvar