diff --git a/controllers/application.go b/controllers/application.go index 3d167db3..27e378c2 100644 --- a/controllers/application.go +++ b/controllers/application.go @@ -50,7 +50,8 @@ func (c *ApiController) GetApplications() { } if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedApplications(applications, userId) @@ -59,13 +60,15 @@ func (c *ApiController) GetApplications() { limit := util.ParseInt(limit) count, err := object.GetApplicationCount(owner, field, value) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } paginator := pagination.SetPaginator(c.Ctx, limit, count) app, err := object.GetPaginationApplications(owner, paginator.Offset(), limit, field, value, sortField, sortOrder) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } applications := object.GetMaskedApplications(app, userId) @@ -85,7 +88,8 @@ func (c *ApiController) GetApplication() { id := c.Input().Get("id") app, err := object.GetApplication(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedApplication(app, userId) @@ -104,7 +108,8 @@ func (c *ApiController) GetUserApplication() { id := c.Input().Get("id") user, err := object.GetUser(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } if user == nil { @@ -114,7 +119,8 @@ func (c *ApiController) GetUserApplication() { app, err := object.GetApplicationByUser(user) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedApplication(app, userId) @@ -147,7 +153,8 @@ func (c *ApiController) GetOrganizationApplications() { if limit == "" || page == "" { applications, err := object.GetOrganizationApplications(owner, organization) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedApplications(applications, userId) diff --git a/controllers/auth.go b/controllers/auth.go index 7b60a6c6..36eeaa56 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -756,7 +756,8 @@ func (c *ApiController) HandleSamlLogin() { func (c *ApiController) HandleOfficialAccountEvent() { respBytes, err := ioutil.ReadAll(c.Ctx.Request.Body) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } var data struct { @@ -766,7 +767,8 @@ func (c *ApiController) HandleOfficialAccountEvent() { } err = xml.Unmarshal(respBytes, &data) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } lock.Lock() diff --git a/controllers/base.go b/controllers/base.go index 5ef534f5..0097714c 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -79,7 +79,8 @@ func (c *ApiController) getCurrentUser() *object.User { } else { user, err = object.GetUser(userId) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return nil } } return user @@ -112,7 +113,8 @@ func (c *ApiController) GetSessionApplication() *object.Application { } application, err := object.GetApplicationByClientId(clientId.(string)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return nil } return application diff --git a/controllers/cert.go b/controllers/cert.go index 2fa93bc4..44934d4e 100644 --- a/controllers/cert.go +++ b/controllers/cert.go @@ -41,7 +41,8 @@ func (c *ApiController) GetCerts() { if limit == "" || page == "" { maskedCerts, err := object.GetMaskedCerts(object.GetCerts(owner)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedCerts @@ -50,13 +51,15 @@ func (c *ApiController) GetCerts() { limit := util.ParseInt(limit) count, err := object.GetCertCount(owner, field, value) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } paginator := pagination.SetPaginator(c.Ctx, limit, count) certs, err := object.GetMaskedCerts(object.GetPaginationCerts(owner, paginator.Offset(), limit, field, value, sortField, sortOrder)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(certs, paginator.Nums()) @@ -80,7 +83,8 @@ func (c *ApiController) GetGlobleCerts() { if limit == "" || page == "" { maskedCerts, err := object.GetMaskedCerts(object.GetGlobleCerts()) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedCerts @@ -89,13 +93,15 @@ func (c *ApiController) GetGlobleCerts() { limit := util.ParseInt(limit) count, err := object.GetGlobalCertsCount(field, value) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } paginator := pagination.SetPaginator(c.Ctx, limit, count) certs, err := object.GetMaskedCerts(object.GetPaginationGlobalCerts(paginator.Offset(), limit, field, value, sortField, sortOrder)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(certs, paginator.Nums()) @@ -113,7 +119,8 @@ func (c *ApiController) GetCert() { id := c.Input().Get("id") cert, err := object.GetCert(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedCert(cert) diff --git a/controllers/chat.go b/controllers/chat.go index 3b041304..2a497048 100644 --- a/controllers/chat.go +++ b/controllers/chat.go @@ -41,7 +41,8 @@ func (c *ApiController) GetChats() { if limit == "" || page == "" { maskedChats, err := object.GetMaskedChats(object.GetChats(owner)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedChats @@ -77,7 +78,8 @@ func (c *ApiController) GetChat() { maskedChat, err := object.GetMaskedChat(object.GetChat(id)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedChat diff --git a/controllers/message.go b/controllers/message.go index 3d4699ff..04fb4880 100644 --- a/controllers/message.go +++ b/controllers/message.go @@ -53,7 +53,8 @@ func (c *ApiController) GetMessages() { } if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedMessages(messages) @@ -89,7 +90,8 @@ func (c *ApiController) GetMessage() { id := c.Input().Get("id") message, err := object.GetMessage(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = object.GetMaskedMessage(message) @@ -100,7 +102,8 @@ func (c *ApiController) ResponseErrorStream(errorText string) { event := fmt.Sprintf("event: myerror\ndata: %s\n\n", errorText) _, err := c.Ctx.ResponseWriter.Write([]byte(event)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } } @@ -196,7 +199,8 @@ func (c *ApiController) GetMessageAnswer() { event := fmt.Sprintf("event: end\ndata: %s\n\n", "end") _, err = c.Ctx.ResponseWriter.Write([]byte(event)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } answer := stringBuilder.String() @@ -204,7 +208,8 @@ func (c *ApiController) GetMessageAnswer() { message.Text = answer _, err = object.UpdateMessage(message.GetId(), message) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } } diff --git a/controllers/model.go b/controllers/model.go index 2ab13f31..916ff7bb 100644 --- a/controllers/model.go +++ b/controllers/model.go @@ -41,7 +41,8 @@ func (c *ApiController) GetModels() { if limit == "" || page == "" { models, err := object.GetModels(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = models @@ -77,7 +78,8 @@ func (c *ApiController) GetModel() { model, err := object.GetModel(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = model diff --git a/controllers/organization.go b/controllers/organization.go index 669308b0..583313e4 100644 --- a/controllers/organization.go +++ b/controllers/organization.go @@ -41,7 +41,8 @@ func (c *ApiController) GetOrganizations() { if limit == "" || page == "" { maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedOrganizations diff --git a/controllers/payment.go b/controllers/payment.go index 47e15a24..16548810 100644 --- a/controllers/payment.go +++ b/controllers/payment.go @@ -42,7 +42,8 @@ func (c *ApiController) GetPayments() { if limit == "" || page == "" { payments, err := object.GetPayments(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = payments @@ -51,13 +52,15 @@ func (c *ApiController) GetPayments() { limit := util.ParseInt(limit) count, err := object.GetPaymentCount(owner, organization, field, value) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } paginator := pagination.SetPaginator(c.Ctx, limit, count) payments, err := object.GetPaginationPayments(owner, organization, paginator.Offset(), limit, field, value, sortField, sortOrder) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(payments, paginator.Nums()) @@ -99,7 +102,8 @@ func (c *ApiController) GetPayment() { payment, err := object.GetPayment(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = payment @@ -190,7 +194,8 @@ func (c *ApiController) NotifyPayment() { } if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } } diff --git a/controllers/permission.go b/controllers/permission.go index b1e7ed6a..82215aba 100644 --- a/controllers/permission.go +++ b/controllers/permission.go @@ -41,7 +41,8 @@ func (c *ApiController) GetPermissions() { if limit == "" || page == "" { permissions, err := object.GetPermissions(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = permissions @@ -50,13 +51,15 @@ func (c *ApiController) GetPermissions() { limit := util.ParseInt(limit) count, err := object.GetPermissionCount(owner, field, value) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } paginator := pagination.SetPaginator(c.Ctx, limit, count) permissions, err := object.GetPaginationPermissions(owner, paginator.Offset(), limit, field, value, sortField, sortOrder) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(permissions, paginator.Nums()) @@ -116,7 +119,8 @@ func (c *ApiController) GetPermission() { permission, err := object.GetPermission(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = permission diff --git a/controllers/plan.go b/controllers/plan.go index 2139305c..09ab18cc 100644 --- a/controllers/plan.go +++ b/controllers/plan.go @@ -41,7 +41,8 @@ func (c *ApiController) GetPlans() { if limit == "" || page == "" { plans, err := object.GetPlans(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = plans @@ -79,13 +80,15 @@ func (c *ApiController) GetPlan() { plan, err := object.GetPlan(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } if includeOption { options, err := object.GetPermissionsByRole(plan.Role) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } for _, option := range options { diff --git a/controllers/pricing.go b/controllers/pricing.go index a726ff59..68ec3818 100644 --- a/controllers/pricing.go +++ b/controllers/pricing.go @@ -41,7 +41,8 @@ func (c *ApiController) GetPricings() { if limit == "" || page == "" { pricings, err := object.GetPricings(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = pricings @@ -77,7 +78,8 @@ func (c *ApiController) GetPricing() { pricing, err := object.GetPricing(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = pricing diff --git a/controllers/product.go b/controllers/product.go index e0cb6a5b..c7575120 100644 --- a/controllers/product.go +++ b/controllers/product.go @@ -42,7 +42,8 @@ func (c *ApiController) GetProducts() { if limit == "" || page == "" { products, err := object.GetProducts(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = products @@ -78,12 +79,14 @@ func (c *ApiController) GetProduct() { product, err := object.GetProduct(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } err = object.ExtendProductWithProviders(product) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = product diff --git a/controllers/provider.go b/controllers/provider.go index 1f311186..234ce788 100644 --- a/controllers/provider.go +++ b/controllers/provider.go @@ -46,7 +46,8 @@ func (c *ApiController) GetProviders() { if limit == "" || page == "" { providers, err := object.GetProviders(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(object.GetMaskedProviders(providers, isMaskEnabled)) @@ -92,7 +93,8 @@ func (c *ApiController) GetGlobalProviders() { if limit == "" || page == "" { globalProviders, err := object.GetGlobalProviders() if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.ResponseOk(object.GetMaskedProviders(globalProviders, isMaskEnabled)) diff --git a/controllers/record.go b/controllers/record.go index 59a7e707..046efac1 100644 --- a/controllers/record.go +++ b/controllers/record.go @@ -46,7 +46,8 @@ func (c *ApiController) GetRecords() { if limit == "" || page == "" { records, err := object.GetRecords() if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = records @@ -84,12 +85,14 @@ func (c *ApiController) GetRecordsByFilter() { record := &object.Record{} err := util.JsonToStruct(body, record) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } records, err := object.GetRecordsByField(record) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = records diff --git a/controllers/resource.go b/controllers/resource.go index 8f18c477..111bfe2c 100644 --- a/controllers/resource.go +++ b/controllers/resource.go @@ -53,7 +53,8 @@ func (c *ApiController) GetResources() { if limit == "" || page == "" { resources, err := object.GetResources(owner, user) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = resources @@ -86,7 +87,8 @@ func (c *ApiController) GetResource() { resource, err := object.GetResource(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = resource diff --git a/controllers/role.go b/controllers/role.go index b99e9cf3..2ac62095 100644 --- a/controllers/role.go +++ b/controllers/role.go @@ -41,7 +41,8 @@ func (c *ApiController) GetRoles() { if limit == "" || page == "" { roles, err := object.GetRoles(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = roles @@ -77,7 +78,8 @@ func (c *ApiController) GetRole() { role, err := object.GetRole(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = role diff --git a/controllers/session.go b/controllers/session.go index b450bdcb..ebab79b6 100644 --- a/controllers/session.go +++ b/controllers/session.go @@ -41,7 +41,8 @@ func (c *ApiController) GetSessions() { if limit == "" || page == "" { sessions, err := object.GetSessions(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = sessions @@ -76,7 +77,8 @@ func (c *ApiController) GetSingleSession() { session, err := object.GetSingleSession(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = session @@ -155,7 +157,8 @@ func (c *ApiController) IsSessionDuplicated() { isUserSessionDuplicated, err := object.IsSessionDuplicated(id, sessionId) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = &Response{Status: "ok", Msg: "", Data: isUserSessionDuplicated} diff --git a/controllers/subscription.go b/controllers/subscription.go index 03094482..7c1d2827 100644 --- a/controllers/subscription.go +++ b/controllers/subscription.go @@ -41,7 +41,8 @@ func (c *ApiController) GetSubscriptions() { if limit == "" || page == "" { subscriptions, err := object.GetSubscriptions(owner) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = subscriptions @@ -77,7 +78,8 @@ func (c *ApiController) GetSubscription() { subscription, err := object.GetSubscription(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = subscription diff --git a/controllers/syncer.go b/controllers/syncer.go index 4f58e206..c8f7d3c3 100644 --- a/controllers/syncer.go +++ b/controllers/syncer.go @@ -42,7 +42,8 @@ func (c *ApiController) GetSyncers() { if limit == "" || page == "" { organizationSyncers, err := object.GetOrganizationSyncers(owner, organization) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = organizationSyncers @@ -78,7 +79,8 @@ func (c *ApiController) GetSyncer() { syncer, err := object.GetSyncer(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = syncer diff --git a/controllers/token.go b/controllers/token.go index 47850a3a..3708cdbd 100644 --- a/controllers/token.go +++ b/controllers/token.go @@ -43,7 +43,8 @@ func (c *ApiController) GetTokens() { if limit == "" || page == "" { token, err := object.GetTokens(owner, organization) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = token @@ -78,7 +79,8 @@ func (c *ApiController) GetToken() { id := c.Input().Get("id") token, err := object.GetToken(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = token @@ -193,7 +195,8 @@ func (c *ApiController) GetOAuthToken() { host := c.Ctx.Request.Host oAuthtoken, err := object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, refreshToken, tag, avatar, c.GetAcceptLanguage()) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = oAuthtoken @@ -236,7 +239,8 @@ func (c *ApiController) RefreshToken() { refreshToken2, err := object.RefreshToken(grantType, refreshToken, scope, clientId, clientSecret, host) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = refreshToken2 @@ -276,7 +280,8 @@ func (c *ApiController) IntrospectToken() { } application, err := object.GetApplicationByClientId(clientId) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } if application == nil || application.ClientSecret != clientSecret { @@ -289,7 +294,8 @@ func (c *ApiController) IntrospectToken() { } token, err := object.GetTokenByTokenAndApplication(tokenValue, application.Name) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } if token == nil { diff --git a/controllers/user.go b/controllers/user.go index 28dd8cce..3e5f4854 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -41,7 +41,8 @@ func (c *ApiController) GetGlobalUsers() { if limit == "" || page == "" { maskedUsers, err := object.GetMaskedUsers(object.GetGlobalUsers()) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedUsers @@ -101,7 +102,8 @@ func (c *ApiController) GetUsers() { maskedUsers, err := object.GetMaskedUsers(object.GetUsers(owner)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedUsers @@ -153,7 +155,8 @@ func (c *ApiController) GetUser() { if userId != "" && owner != "" { userFromUserId, err = object.GetUserByUserId(owner, userId) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } id = util.GetId(userFromUserId.Owner, userFromUserId.Name) @@ -165,7 +168,8 @@ func (c *ApiController) GetUser() { organization, err := object.GetOrganization(util.GetId("admin", owner)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } if !organization.IsProfilePublic { @@ -190,18 +194,21 @@ func (c *ApiController) GetUser() { } if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } user.MultiFactorAuths = object.GetAllMfaProps(user, true) err = object.ExtendUserWithRolesAndPermissions(user) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } maskedUser, err := object.GetMaskedUser(user) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedUser @@ -498,7 +505,8 @@ func (c *ApiController) GetSortedUsers() { maskedUsers, err := object.GetMaskedUsers(object.GetSortedUsers(owner, sorter, limit)) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = maskedUsers diff --git a/controllers/util.go b/controllers/util.go index 28521795..f4c94bc2 100644 --- a/controllers/util.go +++ b/controllers/util.go @@ -97,7 +97,8 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) { user, err := object.GetUser(userId) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return nil, false } if user == nil { diff --git a/controllers/webhook.go b/controllers/webhook.go index 13e24451..64091ce1 100644 --- a/controllers/webhook.go +++ b/controllers/webhook.go @@ -42,7 +42,8 @@ func (c *ApiController) GetWebhooks() { if limit == "" || page == "" { webhooks, err := object.GetWebhooks(owner, organization) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = webhooks @@ -79,7 +80,8 @@ func (c *ApiController) GetWebhook() { webhook, err := object.GetWebhook(id) if err != nil { - panic(err) + c.ResponseError(err.Error()) + return } c.Data["json"] = webhook diff --git a/web/src/AdapterEditPage.js b/web/src/AdapterEditPage.js index efcb0cf9..bd0c2367 100644 --- a/web/src/AdapterEditPage.js +++ b/web/src/AdapterEditPage.js @@ -76,6 +76,10 @@ class AdapterEditPage extends React.Component { getModels(organizationName) { ModelBackend.getModels(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ models: res, }); diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index 59765462..475cc645 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -118,20 +118,25 @@ class ApplicationEditPage extends React.Component { getApplication() { ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - if (application === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } - if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) { - application.grantTypes = ["authorization_code"]; + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + + if (res.grantTypes === null || res.grantTypes === undefined || res.grantTypes.length === 0) { + res.grantTypes = ["authorization_code"]; } this.setState({ - application: application, + application: res, }); - this.getCerts(application.organization); + this.getCerts(res.organization); }); } diff --git a/web/src/CertEditPage.js b/web/src/CertEditPage.js index 628d063c..15f51755 100644 --- a/web/src/CertEditPage.js +++ b/web/src/CertEditPage.js @@ -44,14 +44,19 @@ class CertEditPage extends React.Component { getCert() { CertBackend.getCert(this.state.owner, this.state.certName) - .then((cert) => { - if (cert === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - cert: cert, + cert: res, }); }); } diff --git a/web/src/ChatEditPage.js b/web/src/ChatEditPage.js index 87231280..fc31c5a5 100644 --- a/web/src/ChatEditPage.js +++ b/web/src/ChatEditPage.js @@ -40,17 +40,21 @@ class ChatEditPage extends React.Component { getChat() { ChatBackend.getChat("admin", this.state.chatName) - .then((chat) => { - if (chat === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - chat: chat, + chat: res, }); - this.getUsers(chat.organization); + this.getUsers(res.organization); }); } @@ -66,6 +70,11 @@ class ChatEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ users: res, }); diff --git a/web/src/EntryPage.js b/web/src/EntryPage.js index 814deb8e..5167270e 100644 --- a/web/src/EntryPage.js +++ b/web/src/EntryPage.js @@ -74,8 +74,12 @@ class EntryPage extends React.Component { }); ApplicationBackend.getApplication("admin", pricing.application) - .then((application) => { - const themeData = application !== null ? Setting.getThemeData(application.organizationObj, application) : Conf.ThemeDefault; + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + const themeData = res !== null ? Setting.getThemeData(res.organizationObj, res) : Conf.ThemeDefault; this.props.updataThemeData(themeData); }); }; diff --git a/web/src/MessageEditPage.js b/web/src/MessageEditPage.js index a71fe31b..6a92827d 100644 --- a/web/src/MessageEditPage.js +++ b/web/src/MessageEditPage.js @@ -45,17 +45,20 @@ class MessageEditPage extends React.Component { getMessage() { MessageBackend.getMessage("admin", this.state.messageName) - .then((message) => { - if (message === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } - + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - message: message, + message: res, }); - this.getUsers(message.organization); + this.getUsers(res.organization); }); } @@ -80,6 +83,10 @@ class MessageEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ users: res, }); diff --git a/web/src/ModelEditPage.js b/web/src/ModelEditPage.js index b396a3d6..0548e6e8 100644 --- a/web/src/ModelEditPage.js +++ b/web/src/ModelEditPage.js @@ -47,14 +47,19 @@ class ModelEditPage extends React.Component { getModel() { ModelBackend.getModel(this.state.organizationName, this.state.modelName) - .then((model) => { - if (model === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - model: model, + model: res, }); }); } diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index 52e24b4f..7e4fbab1 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -68,9 +68,14 @@ class OrganizationEditPage extends React.Component { getApplications() { ApplicationBackend.getApplicationsByOrganization("admin", this.state.organizationName) - .then((applications) => { + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - applications: applications, + applications: res, }); }); } diff --git a/web/src/PermissionEditPage.js b/web/src/PermissionEditPage.js index bca97d13..5f8e5b98 100644 --- a/web/src/PermissionEditPage.js +++ b/web/src/PermissionEditPage.js @@ -49,21 +49,26 @@ class PermissionEditPage extends React.Component { getPermission() { PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName) - .then((permission) => { - if (permission === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - permission: permission, + permission: res, }); - this.getUsers(permission.owner); - this.getRoles(permission.owner); - this.getModels(permission.owner); - this.getResources(permission.owner); - this.getModel(permission.owner, permission.model); + this.getUsers(res.owner); + this.getRoles(res.owner); + this.getModels(res.owner); + this.getResources(res.owner); + this.getModel(res.owner, res.model); }); } @@ -79,6 +84,10 @@ class PermissionEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ users: res, }); @@ -88,6 +97,10 @@ class PermissionEditPage extends React.Component { getRoles(organizationName) { RoleBackend.getRoles(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ roles: res, }); @@ -97,6 +110,10 @@ class PermissionEditPage extends React.Component { getModels(organizationName) { ModelBackend.getModels(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ models: res, }); @@ -106,6 +123,10 @@ class PermissionEditPage extends React.Component { getModel(organizationName, modelName) { ModelBackend.getModel(organizationName, modelName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ model: res, }); diff --git a/web/src/PlanEditPage.js b/web/src/PlanEditPage.js index 6fd86e9c..b12002f9 100644 --- a/web/src/PlanEditPage.js +++ b/web/src/PlanEditPage.js @@ -64,6 +64,10 @@ class PlanEditPage extends React.Component { getRoles(organizationName) { RoleBackend.getRoles(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ roles: res, }); @@ -73,6 +77,10 @@ class PlanEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ users: res, }); diff --git a/web/src/PricingEditPage.js b/web/src/PricingEditPage.js index e07b726e..6683ed30 100644 --- a/web/src/PricingEditPage.js +++ b/web/src/PricingEditPage.js @@ -49,22 +49,31 @@ class PricingEditPage extends React.Component { getPricing() { PricingBackend.getPricing(this.state.organizationName, this.state.pricingName) - .then((pricing) => { - if (pricing === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - pricing: pricing, + pricing: res, }); - this.getPlans(pricing.owner); + this.getPlans(res.owner); }); } getPlans(organizationName) { PlanBackend.getPlans(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ plans: res, }); @@ -109,9 +118,13 @@ class PricingEditPage extends React.Component { getUserApplication() { ApplicationBackend.getUserApplication(this.state.organizationName, this.state.userName) - .then((application) => { + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - application: application, + application: res, }); }); } diff --git a/web/src/ProductBuyPage.js b/web/src/ProductBuyPage.js index af9dec0e..23ed3a0c 100644 --- a/web/src/ProductBuyPage.js +++ b/web/src/ProductBuyPage.js @@ -41,9 +41,14 @@ class ProductBuyPage extends React.Component { } ProductBackend.getProduct(this.props.account.owner, this.state.productName) - .then((product) => { + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - product: product, + product: res, }); }); } diff --git a/web/src/RoleEditPage.js b/web/src/RoleEditPage.js index 8a2a130e..03543577 100644 --- a/web/src/RoleEditPage.js +++ b/web/src/RoleEditPage.js @@ -42,18 +42,22 @@ class RoleEditPage extends React.Component { getRole() { RoleBackend.getRole(this.state.organizationName, this.state.roleName) - .then((role) => { - if (role === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - role: role, + role: res, }); - this.getUsers(role.owner); - this.getRoles(role.owner); + this.getUsers(res.owner); + this.getRoles(res.owner); }); } @@ -69,6 +73,10 @@ class RoleEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ users: res, }); @@ -78,6 +86,10 @@ class RoleEditPage extends React.Component { getRoles(organizationName) { RoleBackend.getRoles(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ roles: res, }); diff --git a/web/src/SubscriptionEditPage.js b/web/src/SubscriptionEditPage.js index 38dfc7b7..6d0bbf4d 100644 --- a/web/src/SubscriptionEditPage.js +++ b/web/src/SubscriptionEditPage.js @@ -46,18 +46,23 @@ class SubscriptionEditPage extends React.Component { getSubscription() { SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName) - .then((subscription) => { - if (subscription === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - subscription: subscription, + subscription: res, }); - this.getUsers(subscription.owner); - this.getPlanes(subscription.owner); + this.getUsers(res.owner); + this.getPlanes(res.owner); }); } @@ -73,6 +78,10 @@ class SubscriptionEditPage extends React.Component { getUsers(organizationName) { UserBackend.getUsers(organizationName) .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ users: res, }); diff --git a/web/src/SyncerEditPage.js b/web/src/SyncerEditPage.js index 373aaacc..4df4b102 100644 --- a/web/src/SyncerEditPage.js +++ b/web/src/SyncerEditPage.js @@ -47,14 +47,19 @@ class SyncerEditPage extends React.Component { getSyncer() { SyncerBackend.getSyncer("admin", this.state.syncerName) - .then((syncer) => { - if (syncer === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - syncer: syncer, + syncer: res, }); }); } diff --git a/web/src/TokenEditPage.js b/web/src/TokenEditPage.js index 72c92101..77a876d0 100644 --- a/web/src/TokenEditPage.js +++ b/web/src/TokenEditPage.js @@ -35,14 +35,19 @@ class TokenEditPage extends React.Component { getToken() { TokenBackend.getToken("admin", this.state.tokenName) - .then((token) => { - if (token === null) { + .then((res) => { + if (res === null) { this.props.history.push("/404"); return; } + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - token: token, + token: res, }); }); } diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 0f741305..6e8982aa 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -121,13 +121,17 @@ class UserEditPage extends React.Component { getUserApplication() { ApplicationBackend.getUserApplication(this.state.organizationName, this.state.userName) - .then((application) => { + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - application: application, + application: res, }); this.setState({ - isGroupsVisible: application.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible), + isGroupsVisible: res.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible), }); }); } diff --git a/web/src/auth/ForgetPage.js b/web/src/auth/ForgetPage.js index 7c09d0bb..9d903565 100644 --- a/web/src/auth/ForgetPage.js +++ b/web/src/auth/ForgetPage.js @@ -63,8 +63,12 @@ class ForgetPage extends React.Component { } ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - this.onUpdateApplication(application); + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.onUpdateApplication(res); }); } getApplicationObj() { diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index 1e1e6c8e..aa76eb8a 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -159,8 +159,12 @@ class LoginPage extends React.Component { if (this.state.owner === null || this.state.type === "saml") { ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - this.onUpdateApplication(application); + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.onUpdateApplication(res); }); } else { OrganizationBackend.getDefaultApplication("admin", this.state.owner) diff --git a/web/src/auth/MfaSetupPage.js b/web/src/auth/MfaSetupPage.js index 3bfb663e..2999a05d 100644 --- a/web/src/auth/MfaSetupPage.js +++ b/web/src/auth/MfaSetupPage.js @@ -188,10 +188,14 @@ class MfaSetupPage extends React.Component { } ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - if (application !== null) { + .then((res) => { + if (res !== null) { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } this.setState({ - application: application, + application: res, }); } else { Setting.showMessage("error", i18next.t("mfa:Failed to get application")); diff --git a/web/src/auth/PromptPage.js b/web/src/auth/PromptPage.js index 50183c73..d95539e6 100644 --- a/web/src/auth/PromptPage.js +++ b/web/src/auth/PromptPage.js @@ -49,9 +49,14 @@ class PromptPage extends React.Component { const organizationName = this.props.account.owner; const userName = this.props.account.name; UserBackend.getUser(organizationName, userName) - .then((user) => { + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.setState({ - user: user, + user: res, }); }); } @@ -62,10 +67,15 @@ class PromptPage extends React.Component { } ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - this.onUpdateApplication(application); + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + + this.onUpdateApplication(res); this.setState({ - application: application, + application: res, }); }); } diff --git a/web/src/auth/ResultPage.js b/web/src/auth/ResultPage.js index 68959dd1..58715f57 100644 --- a/web/src/auth/ResultPage.js +++ b/web/src/auth/ResultPage.js @@ -43,10 +43,14 @@ class ResultPage extends React.Component { } ApplicationBackend.getApplication("admin", this.state.applicationName) - .then((application) => { - this.onUpdateApplication(application); + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + this.onUpdateApplication(res); this.setState({ - application: application, + application: res, }); }); } diff --git a/web/src/auth/SignupPage.js b/web/src/auth/SignupPage.js index 7754a72e..91682df4 100644 --- a/web/src/auth/SignupPage.js +++ b/web/src/auth/SignupPage.js @@ -108,8 +108,13 @@ class SignupPage extends React.Component { } ApplicationBackend.getApplication("admin", applicationName) - .then((application) => { - this.onUpdateApplication(application); + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + + this.onUpdateApplication(res); }); } diff --git a/web/src/common/modal/CropperDivModal.js b/web/src/common/modal/CropperDivModal.js index 40dea7d6..791ae79e 100644 --- a/web/src/common/modal/CropperDivModal.js +++ b/web/src/common/modal/CropperDivModal.js @@ -127,6 +127,11 @@ export const CropperDivModal = (props) => { setLoading(true); ResourceBackend.getResources(user.owner, user.name, "", "", "", "", "", "") .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + setLoading(false); + return; + } setLoading(false); setOptions(getOptions(res)); }); diff --git a/web/src/locales/de/data.json b/web/src/locales/de/data.json index 337146ff..fe934fd9 100644 --- a/web/src/locales/de/data.json +++ b/web/src/locales/de/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Preisseite URL kopieren", "Edit Pricing": "Edit Pricing", "Free": "Kostenlos", + "Failed to get plans": "Es konnten keine Pläne abgerufen werden", "Getting started": "Loslegen", "New Pricing": "New Pricing", "Trial duration": "Testphase Dauer", diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index 8d80be09..f463eb31 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Copy pricing page URL", "Edit Pricing": "Edit Pricing", "Free": "Free", + "Failed to get plans": "Failed to get plans", "Getting started": "Getting started", "New Pricing": "New Pricing", "Trial duration": "Trial duration", diff --git a/web/src/locales/es/data.json b/web/src/locales/es/data.json index 08fe950c..3713d094 100644 --- a/web/src/locales/es/data.json +++ b/web/src/locales/es/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Copiar URL de la página de precios", "Edit Pricing": "Edit Pricing", "Free": "Gratis", + "Failed to get plans": "No se pudieron obtener los planes", "Getting started": "Empezar", "New Pricing": "New Pricing", "Trial duration": "Duración del período de prueba", diff --git a/web/src/locales/fr/data.json b/web/src/locales/fr/data.json index 6bdf9f13..a00bd48d 100644 --- a/web/src/locales/fr/data.json +++ b/web/src/locales/fr/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Copier l'URL de la page tarifs", "Edit Pricing": "Edit Pricing", "Free": "Gratuit", + "Failed to get plans": "Échec de l'obtention des plans", "Getting started": "Commencer", "New Pricing": "New Pricing", "Trial duration": "Durée de l'essai", diff --git a/web/src/locales/id/data.json b/web/src/locales/id/data.json index 857e0760..b3d2e447 100644 --- a/web/src/locales/id/data.json +++ b/web/src/locales/id/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Salin URL halaman harga", "Edit Pricing": "Edit Pricing", "Free": "Gratis", + "Failed to get plans": "Gagal mendapatkan rencana", "Getting started": "Mulai", "New Pricing": "New Pricing", "Trial duration": "Durasi percobaan", diff --git a/web/src/locales/ja/data.json b/web/src/locales/ja/data.json index f9895dd4..c49d71ed 100644 --- a/web/src/locales/ja/data.json +++ b/web/src/locales/ja/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "価格ページのURLをコピー", "Edit Pricing": "Edit Pricing", "Free": "無料", + "Failed to get plans": "計画の取得に失敗しました", "Getting started": "はじめる", "New Pricing": "New Pricing", "Trial duration": "トライアル期間の長さ", diff --git a/web/src/locales/ko/data.json b/web/src/locales/ko/data.json index d6b642fb..bd472d19 100644 --- a/web/src/locales/ko/data.json +++ b/web/src/locales/ko/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "가격 페이지 URL 복사", "Edit Pricing": "Edit Pricing", "Free": "무료", + "Failed to get plans": "계획을 가져오지 못했습니다.", "Getting started": "시작하기", "New Pricing": "New Pricing", "Trial duration": "체험 기간", diff --git a/web/src/locales/pt/data.json b/web/src/locales/pt/data.json index e4b3f8cf..b815bd3c 100644 --- a/web/src/locales/pt/data.json +++ b/web/src/locales/pt/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Sao chép URL trang bảng giá", "Edit Pricing": "Edit Pricing", "Free": "Miễn phí", + "Failed to get plans": "Falha ao obter planos", "Getting started": "Bắt đầu", "New Pricing": "New Pricing", "Trial duration": "Thời gian thử nghiệm", diff --git a/web/src/locales/ru/data.json b/web/src/locales/ru/data.json index 615b9812..2fb56684 100644 --- a/web/src/locales/ru/data.json +++ b/web/src/locales/ru/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Скопировать URL прайс-листа", "Edit Pricing": "Edit Pricing", "Free": "Бесплатно", + "Failed to get plans": "Не удалось получить планы", "Getting started": "Выьрать план", "New Pricing": "New Pricing", "Trial duration": "Продолжительность пробного периода", diff --git a/web/src/locales/vi/data.json b/web/src/locales/vi/data.json index 24e2d19c..eade073e 100644 --- a/web/src/locales/vi/data.json +++ b/web/src/locales/vi/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "Sao chép URL trang bảng giá", "Edit Pricing": "Edit Pricing", "Free": "Miễn phí", + "Failed to get plans": "Không thể lấy được các kế hoạch", "Getting started": "Bắt đầu", "New Pricing": "New Pricing", "Trial duration": "Thời gian thử nghiệm", diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index 62df0e32..81ee4a5a 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -569,6 +569,7 @@ "Copy pricing page URL": "复制定价页面链接", "Edit Pricing": "编辑定价", "Free": "免费", + "Failed to get plans": "未能获取计划", "Getting started": "开始使用", "New Pricing": "添加定价", "Trial duration": "试用期时长", diff --git a/web/src/pricing/PricingPage.js b/web/src/pricing/PricingPage.js index 250e1bcb..9299f4ab 100644 --- a/web/src/pricing/PricingPage.js +++ b/web/src/pricing/PricingPage.js @@ -64,6 +64,11 @@ class PricingPage extends React.Component { Promise.all(plans) .then(results => { + const hasError = results.some(result => result.status === "error"); + if (hasError) { + Setting.showMessage("error", `${i18next.t("Failed to get plans")}`); + return; + } this.setState({ plans: results, loading: false, @@ -81,6 +86,11 @@ class PricingPage extends React.Component { PricingBackend.getPricing(this.state.owner, pricingName) .then((result) => { + if (result.status === "error") { + Setting.showMessage("error", result.msg); + return; + } + this.setState({ loading: false, pricing: result,