ソースを参照

Specify error responses

Use error classes to specify the error codes and body.
master
コミット
3ef32e6025
1個のファイルの変更7行の追加2行の削除
  1. +7
    -2
      src/modules/git/Git.service.ts

+ 7
- 2
src/modules/git/Git.service.ts ファイルの表示

@@ -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');
}
}

読み込み中…
キャンセル
保存