<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to throw multiple errors with a function called by CAP handler? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaa-p/12774072#M4795659</link>
    <description>&lt;P&gt;HI Mikhail,&lt;/P&gt;&lt;P&gt;An example rejecting with multiple errors in before handler is here: &lt;A href="https://cap.cloud.sap/docs/node.js/core-services#srv-handle-event" target="test_blank"&gt;https://cap.cloud.sap/docs/node.js/core-services#srv-handle-event&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;// before phase &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;await Promise.all (matching .before handlers) &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if (req.errors) throw req.reject() // without args&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vitaly&lt;/P&gt;</description>
    <pubDate>Mon, 04 Sep 2023 13:19:12 GMT</pubDate>
    <dc:creator>vitaly_kozyura</dc:creator>
    <dc:date>2023-09-04T13:19:12Z</dc:date>
    <item>
      <title>How to throw multiple errors with a function called by CAP handler?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaq-p/12774071</link>
      <description>&lt;P&gt;Hi colleagues,&lt;/P&gt;
  &lt;P&gt;usually if multiple errors are expected we throw it like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;srv.on('CREATE', 'myEntity' req =&amp;gt; {&lt;BR /&gt;   if (true) {
    req.error(400, 'nope 1');
    req.error(400, 'nope 2');
    return;
  }&lt;BR /&gt;})&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Sometimes though we want to clean up our handler so that it turns into kind of this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;validateBeforeCreateMyEntity(req) {
   if (true) {
     req.error(400, 'nope 1');
     req.error(400, 'nope 2');

     // here I want to reject the request with multiple errors which means I probably can't use req.reject as it returns only a single error
   }
}

srv.before('CREATE', 'myEntity' req =&amp;gt; {&lt;BR /&gt;   validateBeforeCreateMyEntity(req);

  // assume we have 50 more lines here&lt;BR /&gt;})&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Is there currently any way to do it?&lt;/P&gt;
  &lt;P&gt;p.s currently in CAP documentation it's just&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;if (req.errors) //&amp;gt; get out somehow...&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 09:16:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaq-p/12774071</guid>
      <dc:creator>epamtiosteel</dc:creator>
      <dc:date>2023-08-28T09:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to throw multiple errors with a function called by CAP handler?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaa-p/12774072#M4795659</link>
      <description>&lt;P&gt;HI Mikhail,&lt;/P&gt;&lt;P&gt;An example rejecting with multiple errors in before handler is here: &lt;A href="https://cap.cloud.sap/docs/node.js/core-services#srv-handle-event" target="test_blank"&gt;https://cap.cloud.sap/docs/node.js/core-services#srv-handle-event&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;// before phase &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;await Promise.all (matching .before handlers) &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if (req.errors) throw req.reject() // without args&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vitaly&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 13:19:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaa-p/12774072#M4795659</guid>
      <dc:creator>vitaly_kozyura</dc:creator>
      <dc:date>2023-09-04T13:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to throw multiple errors with a function called by CAP handler?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaa-p/12774073#M4795660</link>
      <description>&lt;P&gt;for history:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;req.reject(); // without parameters&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;works like a charm.&lt;BR /&gt;&lt;BR /&gt; &lt;SPAN class="mention-scrubbed"&gt;vitaly.kozyura&lt;/SPAN&gt; thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 13:58:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-throw-multiple-errors-with-a-function-called-by-cap-handler/qaa-p/12774073#M4795660</guid>
      <dc:creator>epamtiosteel</dc:creator>
      <dc:date>2023-09-04T13:58:14Z</dc:date>
    </item>
  </channel>
</rss>

