From 32ed97413d911db138c11f66c9c05b569467095d Mon Sep 17 00:00:00 2001 From: mguesdon Date: Thu, 25 Mar 2004 08:27:29 +0000 Subject: [PATCH] * GSWeb.framework/GSWActionRequestHandler.m: o -_handleRequest: partially rewritten for exception handling git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18892 72102866-910b-0410-8b05-ffd578937521 --- GSWeb.framework/GSWActionRequestHandler.m | 99 ++++++++++++++++++----- 1 file changed, 78 insertions(+), 21 deletions(-) diff --git a/GSWeb.framework/GSWActionRequestHandler.m b/GSWeb.framework/GSWActionRequestHandler.m index 3995526..3dd12cf 100644 --- a/GSWeb.framework/GSWActionRequestHandler.m +++ b/GSWeb.framework/GSWActionRequestHandler.m @@ -304,10 +304,18 @@ RCS_ID("$Id$") LOGObjectFnStop(); }; +//-------------------------------------------------------------------- -(GSWAction*)getActionInstanceOfClass:(Class)actionClass withRequest:(GSWRequest*)aRequest { - GSWAction* action=(GSWAction*)[[actionClass alloc]initWithRequest:aRequest]; + GSWAction* action=nil; + + LOGObjectFnStart(); + + action = (GSWAction*)[[actionClass alloc]initWithRequest:aRequest]; + + LOGObjectFnStop(); + return action; } @@ -324,6 +332,7 @@ RCS_ID("$Id$") NSString* actionName=nil; NSString* actionClassName=nil; GSWContext* context=nil; + GSWAction* action=nil; LOGObjectFnStart(); application=[GSWApplication application]; @@ -333,6 +342,8 @@ RCS_ID("$Id$") if (_shouldAddToStatistics) [self registerWillHandleActionRequest]; + [application awake]; + requestHandlerPathArray=[self getRequestHandlerPathForRequest:aRequest]; NSDebugMLLog(@"requests",@"requestHandlerPathArray=%@", requestHandlerPathArray); @@ -354,21 +365,36 @@ RCS_ID("$Id$") resourceManager=[application resourceManager]; appBundle=[resourceManager _appProjectBundle]; [resourceManager _allFrameworkProjectBundles];//So what ? - [application awake]; - GSWAction* action=[self getActionInstanceOfClass:actionClass - withRequest:aRequest]; + action=[self getActionInstanceOfClass:actionClass + withRequest:aRequest]; NSAssert1(action,@"Direct action of class named %@ can't be created", actionClassName); - actionResult=[action performActionNamed:actionName]; + NS_DURING + { + actionResult=[action performActionNamed:actionName]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + response=[application handleActionRequestErrorWithRequest:aRequest + exception:localException + reason:"InvocationError" + requestHanlder:self + actionClassName:actionClassName + actionName:actionName + actionClass:actionClass + actionObject:action]; + [localException raise]; + }; + NS_ENDHANDLER; response=[actionResult generateResponse]; context=[action _context]; - [[NSNotificationCenter defaultCenter]postNotificationName:@"DidHandleRequestNotification" object:context]; [self _setRecordingHeadersToResponse:response @@ -381,19 +407,37 @@ RCS_ID("$Id$") if ([actionClassName length]>0) { - - exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name + exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name (IllegalStateException) reason:[NSString stringWithFormat:@"Can't find action class named '%@'",actionClassName] userInfo:nil]; - + response=[application handleActionRequestErrorWithRequest:aRequest + exception:exception + reason:"InvocationError" + requestHanlder:self + actionClassName:actionClassName + actionName:actionName + actionClass:actionClass + actionObject:action]; } - else { - exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name - reason:[NSString stringWithFormat:@"Can't execute action with path: '%@'",requestHandlerPathArray] - userInfo:nil]; - } - + else + { + exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name (IllegalStateException) + reason:[NSString stringWithFormat:@"Can't execute action with path: '%@'", + requestHandlerPathArray] + userInfo:nil]; + response=[application handleActionRequestErrorWithRequest:aRequest + exception:exception + reason:"InvocationError" + requestHanlder:self + actionClassName:actionClassName + actionName:actionName + actionClass:actionClass + actionObject:action]; + }; + NSDebugMLog(@"Exception=%@",exception); + NSDebugMLog(@"Response=%@",response); [exception raise]; + NSDebugMLog(@"Not raised ? Exception=%@",exception); }; if ([application isCachingEnabled]) { @@ -406,13 +450,26 @@ RCS_ID("$Id$") } NS_HANDLER { - LOGException(@"%@ (%@)",localException,[localException reason]); - if (!context) - context=[GSWApp _context]; - response=[application handleException:localException - inContext:context]; - //TODO + NSDebugMLog(@"EXCEPTION localException=%@",localException); + if (!response) + { + if (!context) + { + context=[action _context]; + if (!context) + { + context=[GSWApp _context]; + if (!context) + { + context = [application createContextForRequest:aRequest]; + }; + }; + }; + + response = [self generateErrorResponseWithException:localException + inContext:context]; + }; }; NS_ENDHANDLER; NSDebugMLLog(@"requests",@"response=%@",response);