[Seaside] Callback onError: management

Esteban Maringolo emaringolo at gmail.com
Thu Jul 9 17:09:23 UTC 2020


Dario,

Sorry, in my previous email I didn't notice the onSuccess: wasn't sent
to the right object

html anchor
   onClick: (
    (html jQuery ajax) callback: [
      [ self setupCashCartNominativeFor: aName ] on: Error do: [ self
requestContext respond: [ :r | r internalError respond ]
    ];
    onError: ( script <<( script jQuery: #genericErrorDialogId ) dialog open );
    onSuccess: ( script << (script jQuery: #idContentView) load
html:[:h| self renderContentViewOn: h]));
  with:[ html div class: class; with:[ html paragraph: aName greaseString]]

As as a side note sometimes dealing with that kind of handling my be
tricky, so instead of performing an ajax action callback, check the
result and then perform another ajax call for the load, you can simply
have a "script:" callback, this will execute the block in the server
and then you can do everything in a single roundtrip, this has also
the convenience of having a "shorter" (in terms of code) click
handler, since it only has the call to the script callback URL.

E.g.:
html anchor
 onClick: (html jQuery ajax script:[ :script |
  [
   self setupCashCartNominativeFor: aName.
  (script << (script jQuery: #idContentView)) replaceWith: [:h| self
renderContentViewOn: h ]
  ] on: Error do: [:ex | script << (( script jQuery:
#genericErrorDialogId ) dialog open) ]
 ]);

I don't find this isn't to the best way to work, at least
conceptually, since it will inject a <script> tag in your code, but
sometimes it is too complex to do all the handling or you have to
handle everything within an error handler to return #internalError,
etc. But I admit I use it extensively in some cases.

I played with having a handledAjax: method on JQAjax, that basically
wraps the original callback within an error handler that simply
returns an 500 Internal Error response if the callback throws an
error.

Regards!

Esteban A. Maringolo

On Thu, Jul 9, 2020 at 12:55 PM Esteban Maringolo <emaringolo at gmail.com> wrote:
>
> Ciao Dario,
>
> You must force the return of an HTTP error response.
>
> on: Error do:[  self requestContext respond:[ :r | r internalError respond ] ]
>
> Regards!
>
> Esteban A. Maringolo
>
> On Thu, Jul 9, 2020 at 12:41 PM Dario Romano Trussardi
> <dario.trussardi65 at gmail.com> wrote:
> >
> > Ciao,
> >
> > i development with Seaside 3.3 into Pharo 703.
> >
> > I have an anchor with specific ajax callback:   block.
> > Now Iā€™m interested to rendering different data if the callback code erase some error or not.
> > I do some test with this code but the onError: script data is always rendering.
> >
> >
> > renderSubTableAnchorFor: aName class: class on: html
> >
> > html anchor
> > onClick:( html jQuery script:[ :script |
> > script << html jQuery ajax
> > callback:[ [ self setupCashCartNominativeFor: aName ] ā€œ it can generate error ā€œ
> > on: Error do:[ self requestContext respond:[ :r | ā€œ ???? " ] ]];
> >
> > onError:( script <<( script jQuery: #genericErrorDialogId ) dialog open );
> > onSuccess:( script << (script jQuery: #idContentView) load html:[:h| self renderContentViewOn: h ])]);
> >
> > with:[ html div class: class;
> > with:[ html paragraph: aName greaseString]]
> >
> >
> > Forget something !?
> >
> > Some considerations ?
> >
> > Thanks,
> >
> > Dario
> > _______________________________________________
> > seaside mailing list
> > seaside at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


More information about the seaside mailing list