Skip to content

Commit c0f998f

Browse files
committed
use ApplicationError's
1 parent 82c6986 commit c0f998f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

components/server/src/api/configuration-service-api.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ListConfigurationsResponse,
2020
} from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
2121
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";
22+
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
2223

2324
@injectable()
2425
export class ConfigurationServiceAPI implements ServiceImpl<typeof ConfigurationServiceInterface> {
@@ -34,13 +35,13 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
3435
context: HandlerContext,
3536
): Promise<CreateConfigurationResponse> {
3637
if (!req.organizationId) {
37-
throw new Error("organizationId is required");
38+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
3839
}
3940
if (!req.cloneUrl) {
40-
throw new Error("cloneUrl is required");
41+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "cloneUrl is required");
4142
}
4243
if (!req.name) {
43-
throw new Error("name is required");
44+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "name is required");
4445
}
4546

4647
const project = await this.projectService.createProject(
@@ -61,7 +62,7 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
6162

6263
async getConfiguration(req: GetConfigurationRequest, context: HandlerContext) {
6364
if (!req.configurationId) {
64-
throw new Error("configurationId is required");
65+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "configurationId is required");
6566
}
6667

6768
const project = await this.projectService.getProject(context.user.id, req.configurationId);
@@ -73,7 +74,7 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
7374

7475
async listConfigurations(req: ListConfigurationsRequest, context: HandlerContext) {
7576
if (!req.organizationId) {
76-
throw new Error("organizationId is required");
77+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
7778
}
7879

7980
const { rows, total } = await this.projectService.findProjects(context.user.id, {
@@ -94,7 +95,7 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
9495

9596
async deleteConfiguration(req: DeleteConfigurationRequest, handler: HandlerContext) {
9697
if (!req.configurationId) {
97-
throw new Error("configurationId is required");
98+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "configurationId is required");
9899
}
99100

100101
await this.projectService.deleteProject(handler.user.id, req.configurationId);

0 commit comments

Comments
 (0)