Skip to content

Commit 8a935a4

Browse files
committed
address review comments
1 parent 5100bcd commit 8a935a4

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

components/server/src/auth/auth-provider-service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,14 @@ export class AuthProviderService {
214214
await this.authProviderDB.delete(authProvider);
215215
}
216216

217-
async getAuthProvider(userId: string, id: string): Promise<AuthProviderEntry | undefined> {
217+
/**
218+
* Returns the provider identified by the specified `id`. Throws `NOT_FOUND` error if the resource
219+
* is not found.
220+
*/
221+
async getAuthProvider(userId: string, id: string): Promise<AuthProviderEntry> {
218222
const result = await this.authProviderDB.findById(id);
219223
if (!result) {
220-
return undefined;
224+
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
221225
}
222226

223227
if (result.organizationId) {
@@ -266,7 +270,7 @@ export class AuthProviderService {
266270
const { id, ownerId } = entry;
267271
const existing = (await this.authProviderDB.findByUserId(ownerId)).find((p) => p.id === id);
268272
if (!existing) {
269-
throw new Error("Provider does not exist.");
273+
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
270274
}
271275
const changed =
272276
entry.clientId !== existing.oauth.clientId ||
@@ -325,7 +329,7 @@ export class AuthProviderService {
325329
// TODO can we change this to query for the provider by id and org instead of loading all from org?
326330
const existing = (await this.authProviderDB.findByOrgId(organizationId)).find((p) => p.id === id);
327331
if (!existing) {
328-
throw new Error("Provider does not exist.");
332+
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
329333
}
330334
const changed =
331335
entry.clientId !== existing.oauth.clientId ||
@@ -368,7 +372,7 @@ export class AuthProviderService {
368372
break;
369373
}
370374
if (!urls) {
371-
throw new Error("Unexpected service type.");
375+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "Unexpected service type.");
372376
}
373377
const oauth: AuthProviderEntry["oauth"] = {
374378
...urls,

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,9 +3070,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30703070
const user = await this.checkAndBlockUser("getAuthProvider");
30713071

30723072
const result = await this.authProviderService.getAuthProvider(user.id, id);
3073-
if (!result) {
3074-
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
3075-
}
30763073
return AuthProviderEntry.redact(result);
30773074
}
30783075

@@ -3085,11 +3082,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30853082

30863083
const user = await this.checkAndBlockUser("deleteAuthProvider");
30873084

3085+
// TODO(at) get rid of the additional read here when user-level providers are migrated to org-level.
30883086
const authProvider = await this.authProviderService.getAuthProvider(user.id, id);
3089-
if (!authProvider) {
3090-
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
3091-
}
3092-
30933087
if (authProvider.organizationId) {
30943088
return this.deleteOrgAuthProvider(ctx, { id, organizationId: authProvider.organizationId });
30953089
} else {
@@ -3111,9 +3105,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
31113105
const user = await this.checkAndBlockUser("updateAuthProvider");
31123106

31133107
const authProvider = await this.authProviderService.getAuthProvider(user.id, id);
3114-
if (!authProvider) {
3115-
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Provider resource not found.");
3116-
}
31173108

31183109
if (authProvider.organizationId) {
31193110
return this.updateOrgAuthProvider(ctx, {

0 commit comments

Comments
 (0)