-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[public-api] aligns with latest guidelines #19038
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,28 +366,19 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB { | |
}); | ||
} | ||
|
||
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<void> { | ||
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving logic into service from DB, making sure that update returns updated data |
||
const repo = await this.getOrgSettingsRepo(); | ||
const team = await repo.findOne({ where: { orgId, deleted: false } }); | ||
const update: Partial<OrganizationSettings> = { | ||
defaultWorkspaceImage: settings.defaultWorkspaceImage, | ||
workspaceSharingDisabled: settings.workspaceSharingDisabled, | ||
}; | ||
// Set to null if defaultWorkspaceImage is empty string, so that it can fallback to default image | ||
if (update.defaultWorkspaceImage?.trim() === "") { | ||
update.defaultWorkspaceImage = null; | ||
} | ||
if (!team) { | ||
await repo.insert({ | ||
...update, | ||
return await repo.save({ | ||
...settings, | ||
orgId, | ||
}); | ||
} else { | ||
await repo.save({ | ||
...team, | ||
...update, | ||
}); | ||
} | ||
return await repo.save({ | ||
...team, | ||
...settings, | ||
}); | ||
} | ||
|
||
public async hasActiveSSO(organizationId: string): Promise<boolean> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
*/ | ||
|
||
import { scrubber } from "../util/scrubbing"; | ||
import { Status } from "nice-grpc-common"; | ||
|
||
export class ApplicationError extends Error { | ||
constructor(public readonly code: ErrorCode, message: string, public readonly data?: any) { | ||
|
@@ -24,7 +23,7 @@ export class ApplicationError extends Error { | |
|
||
export namespace ApplicationError { | ||
export function hasErrorCode(e: any): e is Error & { code: ErrorCode; data?: any } { | ||
return e && e.code !== undefined; | ||
return ErrorCode.is(e["code"]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not all errors with code are ApplicationError, we will consider in the past some typeorm and Node.js errors as AppilcationErorrs, while they should be Internal |
||
} | ||
|
||
export async function notFoundToUndefined<T>(p: Promise<T>): Promise<T | undefined> { | ||
|
@@ -37,41 +36,18 @@ export namespace ApplicationError { | |
throw e; | ||
} | ||
} | ||
|
||
export function fromGRPCError(e: any, data?: any): ApplicationError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should never mindlessly pump error like that, we should do proper translation and if we cannot translate use INTERNAL to iterate on it |
||
// Argument e should be ServerErrorResponse | ||
// But to reduce dependency requirement, we use Error here | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
return new ApplicationError(categorizeRPCError(e.code), e.message, data); | ||
} | ||
|
||
export function categorizeRPCError(code?: Status): ErrorCode { | ||
// Mostly align to https://github.com/gitpod-io/gitpod/blob/ef95e6f3ca0bf314c40da1b83251423c2208d175/components/public-api-server/pkg/proxy/errors.go#L25 | ||
switch (code) { | ||
case Status.INVALID_ARGUMENT: | ||
return ErrorCodes.BAD_REQUEST; | ||
case Status.UNAUTHENTICATED: | ||
return ErrorCodes.NOT_AUTHENTICATED; | ||
case Status.PERMISSION_DENIED: | ||
return ErrorCodes.PERMISSION_DENIED; // or UserBlocked | ||
case Status.NOT_FOUND: | ||
return ErrorCodes.NOT_FOUND; | ||
case Status.ALREADY_EXISTS: | ||
return ErrorCodes.CONFLICT; | ||
case Status.FAILED_PRECONDITION: | ||
return ErrorCodes.PRECONDITION_FAILED; | ||
case Status.RESOURCE_EXHAUSTED: | ||
return ErrorCodes.TOO_MANY_REQUESTS; | ||
} | ||
return ErrorCodes.INTERNAL_SERVER_ERROR; | ||
} | ||
} | ||
|
||
export namespace ErrorCode { | ||
export function isUserError(code: number | ErrorCode) { | ||
return code >= 400 && code < 500; | ||
} | ||
export function is(code: any): code is ErrorCode { | ||
if (typeof code !== "number") { | ||
return false; | ||
} | ||
return Object.values(ErrorCodes).includes(code as ErrorCode); | ||
} | ||
} | ||
|
||
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is potentially breaking for old dashboard against new server, but affect is not significant and resolved by the page reload.
Ideally we need to deliver Huiwen's PR to stop worrying about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed that a risk is pretty low, given that update is very rare operation and we deploy to cells in non working hours. Anyway we wait today for #19042 and if it takes longer then we land this one. cc @mustard-mh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mustard-mh I thinkg there is not problem actually, JSON-RPC is backward compatible, i.e. returns undefined value and old dashboard is going to use old gRPC types with optional, so it should not break, does it make sense?