AppHostBase.ServiceExceptionHandler
グローバルハンドラーは、サービス例外のみを処理します。AppHostBase.ExceptionHandler
サービスの外部で発生する例外を処理するには、グローバルハンドラーを設定できます。例:
public override void Configure(Container container)
{
//Handle Exceptions occurring in Services:
this.ServiceExceptionHandler = (request, exception) => {
//log your exceptions here
...
//call default exception handler or prepare your own custom response
return DtoUtils.HandleException(this, request, exception);
};
//Handle Unhandled Exceptions occurring outside of Services,
//E.g. in Request binding or filters:
this.ExceptionHandler = (req, res, operationName, ex) => {
res.Write("Error: {0}: {1}".Fmt(ex.GetType().Name, ex.Message));
res.EndServiceStackRequest(skipHeaders: true);
};
}
非サービス でDTOを作成して応答ストリームにシリアル化するには、IAppHost.ContentTypeFiltersからの要求に対して正しいシリアライザーExceptionHandler
にアクセスして使用する必要があります。
詳細については、エラー処理wikiページを参照してください。