Error Handling

The ywebservices extension provides you with an example of configuration for error handling mechanism defined in the webservicescommons extension.

The main benefits of this mechanism are common error response format and the possibility to map the response status for exceptions.

For details on the Error Handing mechanism see: Error Handling.

Configuration in the /ywebservices/web/webroot/WEB-INF/config/error-config-spring.xml file.

	<bean id="restHandlerExceptionResolver" class="de.hybris.platform.webservicescommons.resolver.RestHandlerExceptionResolver"
		parent="abstractRestHandlerExceptionResolver">
		<property name="propertySpecificKey" value="ywebservices"/>
		<property name="configurationService" ref="configurationService"/>
	</bean>


	<!-- webservice error factory & converters -->

	<alias alias="webserviceErrorFactory" name="defaultWebserviceErrorFactory" />
	<bean id="defaultWebserviceErrorFactory" class="de.hybris.platform.webservicescommons.errors.factory.impl.DefaultWebserviceErrorFactory">
		<property name="converters">
			<list>
				<ref bean="validationErrorConverter" />
				<ref bean="webserviceExceptionConverter" />
				<ref bean="exceptionConverter" />
			</list>
		</property>
	</bean>

	<bean id="abstractLocalizedErrorConverter" abstract="true"
		class="de.hybris.platform.webservicescommons.errors.converters.AbstractLocalizedErrorConverter">
		<property name="messageSource" ref="messageSource" />
	</bean>

	<alias alias="validationErrorConverter" name="defaultValidationErrorConverter" />
	<bean name="defaultValidationErrorConverter" class="de.hybris.platform.webservicescommons.errors.converters.ValidationErrorConverter"
		parent="abstractLocalizedErrorConverter">
		<property name="i18NService" ref="i18NService" />
	</bean>

	<alias alias="webserviceExceptionConverter" name="defaultWebserviceExceptionConverter" />
	<bean name="defaultWebserviceExceptionConverter" class="de.hybris.platform.webservicescommons.errors.converters.WebserviceExceptionConverter" />

Out of the box, the exception mapping is defined through properties declared in the webservicescommons extension. The mapping can be overriden in your own local.properties file. You can also define mappings that are specific to a web context by using a property root different from the global root. This property root is defined by the propertySpecificKey attribute of the RestHandlerExceptionResolver.

Example:

Global mapping (applies to all web contexts) : webservicescommons.resthandlerexceptionresolver.NotFoundException.status=404

ywebservices web context specific mapping (applies only to ywebservices web context): webservicescommons.resthandlerexceptionresolver.ywebservices.NotFoundException.status=404