Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ot editable return 404

to avoid showing "weird" exception to use, so we return HTTP 404 which
is interpreted by frontend
  • Loading branch information
teosarca committed Mar 4, 2017
1 parent 0352a08 commit 1c62727
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.metas.ui.web.exceptions;

import org.adempiere.ad.callout.exceptions.CalloutInitException;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Check;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

Expand Down Expand Up @@ -38,8 +40,31 @@
@ResponseStatus(code = HttpStatus.NOT_FOUND)
public class EntityNotFoundException extends AdempiereException
{
public static final EntityNotFoundException wrapIfNeeded(final Throwable throwable)
{
Check.assumeNotNull(throwable, "throwable not null");

if (throwable instanceof CalloutInitException)
{
return (EntityNotFoundException)throwable;
}

final Throwable cause = extractCause(throwable);
if(cause != throwable)
{
return wrapIfNeeded(cause);
}

return new EntityNotFoundException(extractMessage(throwable), cause);
}

public EntityNotFoundException(final String message)
{
super(message);
}

public EntityNotFoundException(final String message, final Throwable cause)
{
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,21 @@ public JSONDocument create(

final QuickInputDescriptor quickInputDescriptor = quickInputDescriptors.getQuickInputEntityDescriptor(includedDocumentDescriptor);

return QuickInput.builder()
.setQuickInputDescriptor(quickInputDescriptor)
.setRootDocumentPath(rootDocument.getDocumentPath())
.build()
.bindRootDocument(rootDocument)
.assertTargetWritable();
try
{
return QuickInput.builder()
.setQuickInputDescriptor(quickInputDescriptor)
.setRootDocumentPath(rootDocument.getDocumentPath())
.build()
.bindRootDocument(rootDocument)
.assertTargetWritable();
}
catch(Exception ex)
{
// Avoid showing "weird" exception to use, so we return HTTP 404 which is interpreted by frontend
// see https://github.com/metasfresh/metasfresh-webui-frontend/issues/487
throw EntityNotFoundException.wrapIfNeeded(ex);
}
});

commit(quickInput);
Expand Down

0 comments on commit 1c62727

Please sign in to comment.