Changeset 5905


Ignore:
Timestamp:
04/10/12 11:39:50 (12 years ago)
Author:
natan
Message:

Ticket #2603 - Corrigir a camada de sincronizacao da API - Adicao de suporte a exceptions na sincronizacao

Location:
trunk/prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/Sync.php

    r5715 r5905  
    106106    $args = array( $args ); 
    107107 
     108Controller::addFallbackHandler( 0, function($e){ throw $e; } ); 
     109 
    108110foreach( $args as $i => $data ) 
    109111{ 
     
    122124          $dt = prepare( $concept, $id, $dt, $data, $oldIds, $mounted, $synced ); 
    123125 
    124           $result = Controller::put( array( 'concept' => $concept, 'id' => $id ), $dt ); 
     126          try{ 
     127              $result = Controller::put( array( 'concept' => $concept, 'id' => $id ), $dt ); 
     128          } 
     129          catch( Exception $e ){ 
     130              $return[ $uri ] = $e->getMessage(); 
     131              unset( $data[$uri] ); 
     132              continue; 
     133          } 
    125134 
    126135          if( !$result ) 
  • trunk/prototype/api/controller.php

    r5811 r5905  
    2828        static $isConcept = array(); 
    2929        static $hasOne = array(); 
     30        static $fallbackHandlers = array(); 
    3031        static $txID = 0; 
    3132        static $wallet; 
     
    598599        public static function fallback( $exception ) 
    599600        { 
     601            $code = $exception->getCode(); 
     602 
     603            if( isset( self::$fallbackHandlers[ $code ] ) ) 
     604                return self::$fallbackHandlers[ $code ]( $exception ); 
     605 
    600606            error_log( $exception->getMessage() ); 
    601607            return( true ); 
     608        } 
     609 
     610        public static function addFallbackHandler( $code, $function ) 
     611        { 
     612            self::$fallbackHandlers[ $code ] = $function; 
    602613        } 
    603614        /* 
Note: See TracChangeset for help on using the changeset viewer.