@@ -100,7 +100,7 @@ public function create($data)
100100 $ item ->setData ($ data )->save ();
101101 return json_encode ($ item ->getData ());
102102 } catch (\Exception $ e ) {
103- return false ;
103+ return $ this -> getError ( $ e -> getMessage ()) ;
104104 }
105105 }
106106
@@ -118,7 +118,7 @@ public function update($id, $data)
118118 $ item ->load ($ id );
119119
120120 if (!$ item ->getId ()) {
121- return false ;
121+ return $ this -> getError ( ' Item not found ' ) ;
122122 }
123123 $ data = json_decode ($ data , true );
124124 foreach ($ this ->_imagesMap as $ key ) {
@@ -133,7 +133,7 @@ public function update($id, $data)
133133 $ item ->addData ($ data )->save ();
134134 return json_encode ($ item ->getData ());
135135 } catch (\Exception $ e ) {
136- return false ;
136+ return $ this -> getError ( $ e -> getMessage ()) ;
137137 }
138138 }
139139
@@ -152,9 +152,9 @@ public function delete($id)
152152 $ item ->delete ();
153153 return true ;
154154 }
155- return false ;
155+ return $ this -> getError ( ' Something went wrong ' ) ;
156156 } catch (\Exception $ e ) {
157- return false ;
157+ return $ this -> getError ( $ e -> getMessage ()) ;
158158 }
159159 }
160160
@@ -171,11 +171,11 @@ public function get($id)
171171 $ item ->load ($ id );
172172
173173 if (!$ item ->getId ()) {
174- return false ;
174+ return $ this -> getError ( ' Item not found ' ) ;
175175 }
176176 return json_encode ($ item ->getData ());
177177 } catch (\Exception $ e ) {
178- return false ;
178+ return $ this -> getError ( $ e -> getMessage ()) ;
179179 }
180180 }
181181
@@ -193,12 +193,12 @@ public function view($id, $storeId)
193193 $ item ->getResource ()->load ($ item , $ id );
194194
195195 if (!$ item ->isVisibleOnStore ($ storeId )) {
196- return false ;
196+ return $ this -> getError ( ' Item is not visible on this store. ' ) ;
197197 }
198198
199199 return json_encode ($ this ->getDynamicData ($ item ));
200200 } catch (\Exception $ e ) {
201- return false ;
201+ return $ this -> getError ( $ e -> getMessage ()) ;
202202 }
203203 }
204204
@@ -207,4 +207,16 @@ public function view($id, $storeId)
207207 * @return mixed
208208 */
209209 abstract protected function getDynamicData ($ item );
210+
211+ /**
212+ * @param $massage
213+ * @return false|string
214+ */
215+ public function getError ($ massage ) {
216+ $ data = ['error ' => 'true ' ];
217+
218+ $ data ['message ' ] = $ massage ?? '' ;
219+
220+ return json_encode ($ data );
221+ }
210222}
0 commit comments