Exemplo n.º 1
0
        private void MapToRepresentation(Exception e, HttpRequestMessage req)
        {
            if (e is WithContextNOSException)
            {
                ArgumentsRepresentation.Format format = e is BadPersistArgumentsException ? ArgumentsRepresentation.Format.Full : ArgumentsRepresentation.Format.MembersOnly;
                RestControlFlags flags = e is BadPersistArgumentsException ? ((BadPersistArgumentsException)e).Flags : RestControlFlags.DefaultFlags();

                var contextNosException = e as WithContextNOSException;

                if (contextNosException.Contexts.Any(c => c.ErrorCause == Cause.Disabled || c.ErrorCause == Cause.Immutable))
                {
                    representation = NullRepresentation.Create();
                }
                else if (contextNosException.ContextSurface != null)
                {
                    representation = ArgumentsRepresentation.Create(req, contextNosException.ContextSurface, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.Contexts.Any())
                {
                    representation = ArgumentsRepresentation.Create(req, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else
                {
                    representation = NullRepresentation.Create();
                }
            }
            else if (e is ResourceNotFoundNOSException ||
                     e is NotAllowedNOSException ||
                     e is PreconditionFailedNOSException ||
                     e is PreconditionHeaderMissingNOSException ||
                     e is NoContentNOSException)
            {
                representation = NullRepresentation.Create();
            }
            else
            {
                representation = ErrorRepresentation.Create(e);
            }
        }