source: trunk/grails-app/controllers/nl/tno/metagenomics/integration/SynchronizeController.groovy @ 17

Last change on this file since 17 was 17, checked in by robert@…, 13 years ago

Better error handling during synchronization

File size: 1.4 KB
Line 
1package nl.tno.metagenomics.integration
2
3
4class SynchronizeController {
5        def synchronizationService
6       
7        // Show a 'waiting' page and perform a full synchronization afterwards
8    def full = { 
9                def redirectUrl = params.redirect;
10               
11                if( !redirectUrl )
12                        redirectUrl = g.createLink( controller: 'run' );
13               
14                // Set the date of last synchronization to now. Doing it here, prevents the
15                // application of entering an infinite loop if an error occurs:
16                //              /study                  -> redirect to synchronization
17                //              /synchronize    -> fails with an error, redirects to /study
18                //                      etc...
19                // synchronizationService.lastFullSynchronization = new Date();
20                [ url: redirectUrl ]
21        }
22       
23        def perform = {
24                try {
25                        synchronizationService.sessionToken = session.sessionToken
26                        synchronizationService.user = session.user
27       
28                        synchronizationService.fullSynchronization();
29                        render "";
30                } catch( Exception e ) {
31                        // Catch all exceptions, show them to the user (by rendering a text message) and print a stacktrace
32                        def message = e.getMessage();
33                        if( !message || message == 'null' )
34                                message = 'unknown error';
35               
36                        // Show errors in log file             
37                        log.error "Exception during full synchronization: " + message
38                        e.printStackTrace()
39                       
40                        // Give the user a nice error message
41                        response.status = 500;
42                        render "An error occurred during synchronization (" + e.class?.name + "): " + message;
43                }
44        }
45}
Note: See TracBrowser for help on using the repository browser.