question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error handling in done()

See original GitHub issue

Is there a way to handle errors in done() so that the form data in the storage is not cleared?

If the processing fails, I want to offer the user a possibility to re-process the data without having to re-fill the entire form.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
eagle-rcommented, Mar 8, 2018

I still feel this is would be a valuable feature. For my application, I ended up using an approach similar to that suggested by @dbrgn in https://github.com/django/django-formtools/issues/61#issuecomment-199702599.

This worked quite well for me but for it to work with the current codebase, I had to copy/paste the entire render_done() method and then modify it to catch a ValidationError raised by the done() method. Something along the lines of the code below. It’s not very elegant and is specific to my requirements but it should give you an idea,

        try:
            done_response = self.done(final_forms.values(), form_dict=final_forms, **kwargs)
            self.storage.reset()
            return done_response
        except ValidationError as e:
            form.add_error(None, e)
            return self.render(form)
0reactions
HenryMehtacommented, Sep 11, 2019

I still feel this is would be a valuable feature. For my application, I ended up using an approach similar to that suggested by @dbrgn in #61 (comment).

This worked quite well for me but for it to work with the current codebase, I had to copy/paste the entire render_done() method and then modify it to catch a ValidationError raised by the done() method. Something along the lines of the code below. It’s not very elegant and is specific to my requirements but it should give you an idea,

        try:
            done_response = self.done(final_forms.values(), form_dict=final_forms, **kwargs)
            self.storage.reset()
            return done_response
        except ValidationError as e:
            form.add_error(None, e)
            return self.render(form)

This works like a charm

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Error Handling? - Definition from Techopedia
Error handling refers to the response and recovery procedures from error conditions present in a software application. In other words, it is the...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
Promise chains are great at error handling. When a promise rejects, the control jumps to the closest rejection handler.
Read more >
Control flow and error handling - JavaScript - MDN Web Docs
Exception handling statements. You can throw exceptions using the throw statement and handle them using the try...catch statements.
Read more >
Error handling in JavaScript - TutorialsTeacher
JavaScript provides error-handling mechanism to catch runtime errors using try-catch-finally block, similar to other languages like Java or C#. Syntax: try { // ......
Read more >
4. Error Handling - Open Book Project
When the program is running, and the function is called like that, the code that called it will get a string value, as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found