@@ -30,6 +30,25 @@ public final class Event {
3030 private Event () {
3131 }
3232
33+ /**
34+ * check the event type.
35+ *
36+ * @param eventName the event name
37+ * @return the EventError object
38+ */
39+ public static EventError checkEventName (String eventName ) {
40+ if (!isValidName (eventName )) {
41+ return new EventError (ErrorCode .EVENT_NAME_INVALID ,
42+ "Event name can only contains uppercase and lowercase letters, " +
43+ "underscores, number, and is not start with a number. event name: " + eventName );
44+ } else if (eventName .length () > Limit .MAX_LENGTH_OF_NAME ) {
45+ return new EventError (ErrorCode .EVENT_NAME_LENGTH_EXCEED ,
46+ "Event name is too long, the max event type length is " +
47+ Limit .MAX_LENGTH_OF_NAME + "characters. event name: " + eventName );
48+ }
49+ return null ;
50+ }
51+
3352 /**
3453 * check the attribute error.
3554 *
@@ -42,22 +61,22 @@ public static EventError checkAttribute(int currentNumber, String name, Object v
4261 if (currentNumber >= Limit .MAX_NUM_OF_ATTRIBUTES ) {
4362 LOG .error ("reached the max number of attributes limit ("
4463 + Limit .MAX_NUM_OF_ATTRIBUTES + "). and the attribute: " + name + " will not be recorded" );
45- return new EventError (ErrorType .ATTRIBUTE_SIZE_EXCEED ,
64+ return new EventError (ErrorCode .ATTRIBUTE_SIZE_EXCEED ,
4665 StringUtil .clipString ("attribute name: " + name , Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
4766 }
4867 if (name .length () > Limit .MAX_LENGTH_OF_NAME ) {
4968 LOG .error ("attribute : " + name + ", reached the max length of attributes name limit("
5069 + Limit .MAX_LENGTH_OF_NAME + "). current length is:(" + name .length () +
5170 ") and the attribute will not be recorded" );
52- return new EventError (ErrorType .ATTRIBUTE_NAME_LENGTH_EXCEED ,
71+ return new EventError (ErrorCode .ATTRIBUTE_NAME_LENGTH_EXCEED ,
5372 StringUtil .clipString ("attribute name length is:(" + name .length () + ") name is:" + name ,
5473 Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
5574 }
5675 if (!isValidName (name )) {
5776 LOG .error ("attribute : " + name + ", was not valid, attribute name can only contains" +
5877 " uppercase and lowercase letters, underscores, number, and is not start with a number." +
5978 " so the attribute will not be recorded" );
60- return new EventError (ErrorType .ATTRIBUTE_NAME_INVALID ,
79+ return new EventError (ErrorCode .ATTRIBUTE_NAME_INVALID ,
6180 StringUtil .clipString (name , Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
6281 }
6382
@@ -68,7 +87,7 @@ public static EventError checkAttribute(int currentNumber, String name, Object v
6887 + Limit .MAX_LENGTH_OF_VALUE + "). current length is:(" + valueLength +
6988 "). and the attribute will not be recorded, attribute value:" + value );
7089
71- return new EventError (ErrorType .ATTRIBUTE_VALUE_LENGTH_EXCEED ,
90+ return new EventError (ErrorCode .ATTRIBUTE_VALUE_LENGTH_EXCEED ,
7291 StringUtil .clipString ("attribute name:" + name + ", attribute value:" + value ,
7392 Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
7493 }
@@ -88,14 +107,14 @@ public static EventError checkUserAttribute(int currentNumber, String name, Obje
88107 if (currentNumber >= Limit .MAX_NUM_OF_USER_ATTRIBUTES ) {
89108 LOG .error ("reached the max number of user attributes limit ("
90109 + Limit .MAX_NUM_OF_USER_ATTRIBUTES + "). and the user attribute: " + name + " will not be recorded" );
91- return new EventError (ErrorType . ATTRIBUTE_SIZE_EXCEED ,
110+ return new EventError (ErrorCode . USER_ATTRIBUTE_SIZE_EXCEED ,
92111 StringUtil .clipString ("attribute name: " + name , Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
93112 }
94113 if (name .length () > Limit .MAX_LENGTH_OF_NAME ) {
95114 LOG .error ("user attribute : " + name + ", reached the max length of attributes name limit("
96115 + Limit .MAX_LENGTH_OF_NAME + "). current length is:(" + name .length () +
97116 ") and the attribute will not be recorded" );
98- return new EventError (ErrorType . ATTRIBUTE_NAME_LENGTH_EXCEED ,
117+ return new EventError (ErrorCode . USER_ATTRIBUTE_NAME_LENGTH_EXCEED ,
99118 StringUtil .clipString ("user attribute name length is:(" + name .length () + ") name is:" + name ,
100119 Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
101120 }
@@ -106,7 +125,7 @@ public static EventError checkUserAttribute(int currentNumber, String name, Obje
106125 LOG .error ("user attribute : " + name + ", was not valid, user attribute name can only contains" +
107126 " uppercase and lowercase letters, underscores, number, and is not start with a number." +
108127 " so the attribute will not be recorded" );
109- return new EventError (ErrorType . ATTRIBUTE_NAME_INVALID ,
128+ return new EventError (ErrorCode . USER_ATTRIBUTE_NAME_INVALID ,
110129 StringUtil .clipString (name , Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
111130 }
112131 if (value instanceof String ) {
@@ -115,7 +134,7 @@ public static EventError checkUserAttribute(int currentNumber, String name, Obje
115134 LOG .error ("user attribute : " + name + ", reached the max length of attributes value limit ("
116135 + Limit .MAX_LENGTH_OF_USER_VALUE + "). current length is:(" + valueLength +
117136 "). and the attribute will not be recorded, attribute value:" + value );
118- return new EventError (ErrorType . ATTRIBUTE_VALUE_LENGTH_EXCEED ,
137+ return new EventError (ErrorCode . USER_ATTRIBUTE_VALUE_LENGTH_EXCEED ,
119138 StringUtil .clipString ("user attribute name:" + name + ", attribute value:" + value ,
120139 Limit .MAX_LENGTH_OF_ERROR_VALUE , true ));
121140 }
@@ -173,27 +192,63 @@ private Limit() {
173192 }
174193
175194 /**
176- * event error type .
195+ * the event error code constants .
177196 */
178- public static final class ErrorType {
179- private static final String ATTRIBUTE_NAME_INVALID = "_error_name_invalid" ;
180- private static final String ATTRIBUTE_NAME_LENGTH_EXCEED = "_error_name_length_exceed" ;
181- private static final String ATTRIBUTE_VALUE_LENGTH_EXCEED = "_error_value_length_exceed" ;
182- private static final String ATTRIBUTE_SIZE_EXCEED = "_error_attribute_size_exceed" ;
197+ public static final class ErrorCode {
198+ /**
199+ * error code for event name invalid.
200+ */
201+ public static final int EVENT_NAME_INVALID = 1001 ;
202+ /**
203+ * error code for event name length exceed the limit.
204+ */
205+ public static final int EVENT_NAME_LENGTH_EXCEED = 1002 ;
206+ /**
207+ * error code for attribute name length exceed.
208+ */
209+ public static final int ATTRIBUTE_NAME_LENGTH_EXCEED = 2001 ;
210+ /**
211+ * error code for attribute name invalid.
212+ */
213+ public static final int ATTRIBUTE_NAME_INVALID = 2002 ;
214+ /**
215+ * error code for attribute value length exceed.
216+ */
217+ public static final int ATTRIBUTE_VALUE_LENGTH_EXCEED = 2003 ;
218+ /**
219+ * error code for attribute size exceed.
220+ */
221+ public static final int ATTRIBUTE_SIZE_EXCEED = 2004 ;
222+ /**
223+ * error code for user attribute size exceed.
224+ */
225+ public static final int USER_ATTRIBUTE_SIZE_EXCEED = 3001 ;
226+ /**
227+ * error code for user attribute name length exceed.
228+ */
229+ public static final int USER_ATTRIBUTE_NAME_LENGTH_EXCEED = 3002 ;
230+ /**
231+ * error code for user user attribute name invalid.
232+ */
233+ public static final int USER_ATTRIBUTE_NAME_INVALID = 3003 ;
234+ /**
235+ * error code for user attribute value length exceed.
236+ */
237+ public static final int USER_ATTRIBUTE_VALUE_LENGTH_EXCEED = 3004 ;
183238
184- private ErrorType () {
239+ private ErrorCode () {
185240 }
186241 }
187242
188243 /**
189244 * Event for return.
190245 */
191246 public static class EventError {
192- private final String errorType ;
247+ private final int errorCode ;
193248 private final String errorMessage ;
194249
195- EventError (String errorType , String errorMessage ) {
196- this .errorType = errorType ;
250+ EventError (int errorType , String errorMessage ) {
251+ this .errorCode = errorType ;
197252 this .errorMessage = errorMessage ;
198253 }
199254
@@ -202,8 +257,8 @@ public static class EventError {
202257 *
203258 * @return error type
204259 */
205- public String getErrorType () {
206- return errorType ;
260+ public int getErrorCode () {
261+ return errorCode ;
207262 }
208263
209264 /**
@@ -287,6 +342,14 @@ public static final class ReservedAttribute {
287342 * is the first time attribute.
288343 */
289344 public static final String IS_FIRST_TIME = "_is_first_time" ;
345+ /**
346+ * is the error code attribute.
347+ */
348+ public static final String ERROR_CODE = "_error_code" ;
349+ /**
350+ * is the error message attribute.
351+ */
352+ public static final String ERROR_MESSAGE = "_error_message" ;
290353
291354 private ReservedAttribute () {
292355 }
@@ -346,6 +409,11 @@ public static final class PresetEvent {
346409 */
347410 public static final String PROFILE_SET = "_profile_set" ;
348411
412+ /**
413+ * clickstream error event.
414+ */
415+ public static final String CLICKSTREAM_ERROR = "_clickstream_error" ;
416+
349417 private PresetEvent () {
350418 }
351419 }
0 commit comments