mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
Handle 403 for listGroups and getOrganization (#11044)
Closes: enso-org/cloud-v2#1470 This PR handles 403 responses for certain RemoteBackend endpoints
This commit is contained in:
parent
e77a6067a0
commit
16a4466156
@ -30,6 +30,8 @@ const STATUS_NOT_FOUND = 404
|
||||
const STATUS_SERVER_ERROR = 500
|
||||
/** HTTP status indicating that the request was successful, but the user is not authorized to access. */
|
||||
const STATUS_NOT_AUTHORIZED = 401
|
||||
/** HTTP status indicating that authorized user doesn't have access to the given resource */
|
||||
const STATUS_NOT_ALLOWED = 403
|
||||
|
||||
/** The number of milliseconds in one day. */
|
||||
const ONE_DAY_MS = 86_400_000
|
||||
@ -212,7 +214,9 @@ export default class RemoteBackend extends Backend {
|
||||
override async listUsers(): Promise<readonly backend.User[]> {
|
||||
const path = remoteBackendPaths.LIST_USERS_PATH
|
||||
const response = await this.get<ListUsersResponseBody>(path)
|
||||
if (!responseIsSuccessful(response)) {
|
||||
if (response.status === STATUS_NOT_ALLOWED) {
|
||||
return []
|
||||
} else if (!responseIsSuccessful(response)) {
|
||||
return await this.throw(response, 'listUsersBackendError')
|
||||
} else {
|
||||
return (await response.json()).users
|
||||
@ -367,8 +371,9 @@ export default class RemoteBackend extends Backend {
|
||||
override async getOrganization(): Promise<backend.OrganizationInfo | null> {
|
||||
const path = remoteBackendPaths.GET_ORGANIZATION_PATH
|
||||
const response = await this.get<backend.OrganizationInfo>(path)
|
||||
if (response.status === STATUS_NOT_FOUND) {
|
||||
if ([STATUS_NOT_ALLOWED, STATUS_NOT_FOUND].includes(response.status)) {
|
||||
// Organization info has not yet been created.
|
||||
// or the user is not eligible to create an organization.
|
||||
return null
|
||||
} else if (!responseIsSuccessful(response)) {
|
||||
return await this.throw(response, 'getOrganizationBackendError')
|
||||
@ -1047,7 +1052,9 @@ export default class RemoteBackend extends Backend {
|
||||
override async listUserGroups(): Promise<backend.UserGroupInfo[]> {
|
||||
const path = remoteBackendPaths.LIST_USER_GROUPS_PATH
|
||||
const response = await this.get<backend.UserGroupInfo[]>(path)
|
||||
if (!responseIsSuccessful(response)) {
|
||||
if (response.status === STATUS_NOT_ALLOWED) {
|
||||
return [] as const
|
||||
} else if (!responseIsSuccessful(response)) {
|
||||
return this.throw(response, 'listUserGroupsBackendError')
|
||||
} else {
|
||||
return await response.json()
|
||||
|
Loading…
Reference in New Issue
Block a user