File tree Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,19 @@ type Label struct {
2121 ExclusiveOrder int `yaml:"exclusive_order,omitempty"`
2222}
2323
24+ type ErrInvalidLabelColor struct {
25+ Color string
26+ }
27+
28+ func (e * ErrInvalidLabelColor ) Error () string {
29+ return fmt .Sprintf ("invalid label color: %s" , e .Color )
30+ }
31+
32+ func IsErrInvalidLabelColor (err error ) bool {
33+ _ , ok := err .(* ErrInvalidLabelColor )
34+ return ok
35+ }
36+
2437// NormalizeColor normalizes a color string to a 6-character hex code
2538func NormalizeColor (color string ) (string , error ) {
2639 // normalize case
@@ -32,7 +45,9 @@ func NormalizeColor(color string) (string, error) {
3245 }
3346
3447 if ! colorPattern .MatchString (color ) {
35- return "" , fmt .Errorf ("bad color code: %s" , color )
48+ return "" , & ErrInvalidLabelColor {
49+ Color : color ,
50+ }
3651 }
3752
3853 // convert 3-character shorthand into 6-character version
Original file line number Diff line number Diff line change @@ -52,7 +52,12 @@ func NewLabel(ctx *context.Context) {
5252 ExclusiveOrder : form .ExclusiveOrder ,
5353 }
5454 if err := issues_model .NewLabel (ctx , l ); err != nil {
55- ctx .ServerError ("NewLabel" , err )
55+ if label .IsErrInvalidLabelColor (err ) {
56+ ctx .Flash .Error (err .Error ())
57+ ctx .Redirect (ctx .Org .OrgLink + "/settings/labels" )
58+ } else {
59+ ctx .ServerError ("NewLabel" , err )
60+ }
5661 return
5762 }
5863 ctx .Redirect (ctx .Org .OrgLink + "/settings/labels" )
@@ -79,7 +84,12 @@ func UpdateLabel(ctx *context.Context) {
7984 l .Color = form .Color
8085 l .SetArchived (form .IsArchived )
8186 if err := issues_model .UpdateLabel (ctx , l ); err != nil {
82- ctx .ServerError ("UpdateLabel" , err )
87+ if label .IsErrInvalidLabelColor (err ) {
88+ ctx .Flash .Error (err .Error ())
89+ ctx .Redirect (ctx .Org .OrgLink + "/settings/labels" )
90+ } else {
91+ ctx .ServerError ("UpdateLabel" , err )
92+ }
8393 return
8494 }
8595 ctx .Redirect (ctx .Org .OrgLink + "/settings/labels" )
Original file line number Diff line number Diff line change @@ -119,7 +119,12 @@ func NewLabel(ctx *context.Context) {
119119 Color : form .Color ,
120120 }
121121 if err := issues_model .NewLabel (ctx , l ); err != nil {
122- ctx .ServerError ("NewLabel" , err )
122+ if label .IsErrInvalidLabelColor (err ) {
123+ ctx .Flash .Error (err .Error ())
124+ ctx .Redirect (ctx .Repo .RepoLink + "/labels" )
125+ } else {
126+ ctx .ServerError ("NewLabel" , err )
127+ }
123128 return
124129 }
125130 ctx .Redirect (ctx .Repo .RepoLink + "/labels" )
@@ -146,7 +151,12 @@ func UpdateLabel(ctx *context.Context) {
146151
147152 l .SetArchived (form .IsArchived )
148153 if err := issues_model .UpdateLabel (ctx , l ); err != nil {
149- ctx .ServerError ("UpdateLabel" , err )
154+ if label .IsErrInvalidLabelColor (err ) {
155+ ctx .Flash .Error (err .Error ())
156+ ctx .Redirect (ctx .Repo .RepoLink + "/labels" )
157+ } else {
158+ ctx .ServerError ("UpdateLabel" , err )
159+ }
150160 return
151161 }
152162 ctx .Redirect (ctx .Repo .RepoLink + "/labels" )
You can’t perform that action at this time.
0 commit comments