@@ -3,6 +3,7 @@ package jira
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "net/http"
78 "strconv"
89 "strings"
@@ -63,7 +64,10 @@ func (c *Client) CreateV2(req *CreateRequest) (*CreateResponse, error) {
6364}
6465
6566func (c * Client ) create (req * CreateRequest , ver string ) (* CreateResponse , error ) {
66- data := c .getRequestData (req )
67+ data , err := c .getRequestData (req )
68+ if err != nil {
69+ return nil , err
70+ }
6771
6872 body , err := json .Marshal (& data )
6973 if err != nil {
@@ -103,7 +107,7 @@ func (c *Client) create(req *CreateRequest, ver string) (*CreateResponse, error)
103107 return & out , err
104108}
105109
106- func (* Client ) getRequestData (req * CreateRequest ) * createRequest {
110+ func (* Client ) getRequestData (req * CreateRequest ) ( * createRequest , error ) {
107111 if req .Labels == nil {
108112 req .Labels = []string {}
109113 }
@@ -176,31 +180,36 @@ func (*Client) getRequestData(req *CreateRequest) *createRequest {
176180 }
177181 data .Fields .M .FixVersions = versions
178182 }
179- constructCustomFields (req .CustomFields , & data )
183+ if err := constructCustomFields (req .CustomFields , & data ); err != nil {
184+ return nil , err
185+ }
180186
181- return & data
187+ return & data , nil
182188}
183189
184- func constructCustomFields (fields map [string ]string , data * createRequest ) {
190+ func constructCustomFields (fields map [string ]string , data * createRequest ) error {
185191 if len (fields ) == 0 {
186- return
192+ return nil
187193 }
188194
189195 var configuredFields []IssueTypeField
190196
191197 err := viper .UnmarshalKey ("issue.fields.custom" , & configuredFields )
192198 if err != nil || len (configuredFields ) == 0 {
193- return
199+ return nil
194200 }
195201
196202 data .Fields .M .customFields = make (customField )
197203
198204 for key , val := range fields {
205+ found := false
206+
199207 for _ , configured := range configuredFields {
200208 identifier := strings .ReplaceAll (strings .ToLower (strings .TrimSpace (configured .Name )), " " , "-" )
201209 if identifier != strings .ToLower (key ) {
202210 continue
203211 }
212+ found = true
204213
205214 switch configured .Schema .DataType {
206215 case customFieldFormatOption :
@@ -230,7 +239,12 @@ func constructCustomFields(fields map[string]string, data *createRequest) {
230239 data .Fields .M .customFields [configured .Key ] = val
231240 }
232241 }
242+
243+ if ! found {
244+ return fmt .Errorf ("Invalid custom field specified: %s\n " , key )
245+ }
233246 }
247+ return nil
234248}
235249
236250type createRequest struct {
0 commit comments