From 05dc92857643480da634a72ab31a162386577171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 29 Jun 2020 17:22:50 +0200 Subject: [PATCH] Better handling of errors on trial license request (#14886) * Fix behavior on blank site url on trial requests * Adding trial license error response handling * Changing text based on PR review comments --- api4/license.go | 5 +++++ app/license.go | 4 ++++ i18n/en.json | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/api4/license.go b/api4/license.go index bf1f945e05..4299e7d255 100644 --- a/api4/license.go +++ b/api4/license.go @@ -187,6 +187,11 @@ func requestTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) { Users: usersNumber.Users, } + if trialLicenseRequest.SiteURL == "" { + c.Err = model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.no-site-url.app_error", nil, "", http.StatusBadRequest) + return + } + if err := c.App.Srv().RequestTrialLicense(trialLicenseRequest); err != nil { c.Err = err return diff --git a/app/license.go b/app/license.go index 20f36564ad..99e9becfdb 100644 --- a/app/license.go +++ b/app/license.go @@ -218,6 +218,10 @@ func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *m defer resp.Body.Close() licenseResponse := model.MapFromJson(resp.Body) + if _, ok := licenseResponse["license"]; !ok { + return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, licenseResponse["message"], http.StatusBadRequest) + } + if _, err := s.SaveLicense([]byte(licenseResponse["license"])); err != nil { return err } diff --git a/i18n/en.json b/i18n/en.json index 5f449ec5ab..cc79c14d8f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1504,6 +1504,10 @@ "id": "api.license.request_trial_license.app_error", "translation": "Unable to get a trial license, please try again or contact with support@mattermost.com." }, + { + "id": "api.license.request_trial_license.no-site-url.app_error", + "translation": "Unable to request a trial license. Please configure a Site URL in the web server section of the Mattermost System Console." + }, { "id": "api.marshal_error", "translation": "marshal error"