@@ -214,14 +214,7 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
214214 try {
215215 $ loggerService = $ this ->serviceContainer ->getLoggerService ();
216216 $ loggerService ->debug ("API Called: $ apiName " );
217- // Ensure context is valid
218- if (!isset ($ context ['id ' ]) || empty ($ context ['id ' ])) {
219- $ loggerService ->error ('INVALID_CONTEXT_PASSED ' , ['an ' => ApiEnum::SET_ATTRIBUTE , 'apiName ' => $ apiName ], false );
220- throw new \Error ('TypeError: Invalid context ' );
221- }
222- // set uuid in context
223- $ context ['uuid ' ] = $ this ->getUUIDFromContext ($ context , $ apiName );
224-
217+
225218 if (DataTypeUtil::isString ($ attributesOrAttributeValue )) {
226219 // Validate attributeKey is a string
227220 if (!DataTypeUtil::isString ($ attributesOrAttributeValue )) {
@@ -235,6 +228,11 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
235228 !DataTypeUtil::isBoolean ($ attributeValueOrContext )) {
236229 $ loggerService ->error ("INVALID_PARAM " , ['key ' => $ attributeValueOrContext , 'an ' => ApiEnum::SET_ATTRIBUTE , 'apiName ' => $ apiName , 'type ' => gettype ($ attributeValueOrContext ), 'correctType ' => 'string ' ], false );
237230 throw new \TypeError ('TypeError: attributeValue should be a valid string, number, or boolean ' );
231+ }
232+ // Ensure context is valid
233+ if (!isset ($ context ['id ' ]) || empty ($ context ['id ' ])) {
234+ $ loggerService ->error ('INVALID_CONTEXT_PASSED ' , ['an ' => ApiEnum::SET_ATTRIBUTE , 'apiName ' => $ apiName ], false );
235+ throw new \Error ('TypeError: Invalid context ' );
238236 }
239237
240238 //Get userId using UserIdUtil if aliasing is enabled and gateway service is provided
@@ -247,6 +245,8 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
247245 }
248246 }
249247 $ context ['id ' ] = $ userId ;
248+ // set uuid in context
249+ $ context ['uuid ' ] = $ this ->getUUIDFromContext ($ context , $ apiName );
250250
251251 $ contextModel = new ContextModel ();
252252 $ contextModel ->modelFromDictionary ($ context );
@@ -300,6 +300,8 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
300300 }
301301 }
302302 $ context ['id ' ] = $ userId ;
303+ // set uuid in context
304+ $ context ['uuid ' ] = $ this ->getUUIDFromContext ($ context , $ apiName );
303305
304306 $ contextModel = new ContextModel ();
305307 $ contextModel ->modelFromDictionary ($ context );
0 commit comments