Skip to content

Commit

Permalink
Added kumuluzee-rest exceptions to show-error-message list by default
Browse files Browse the repository at this point in the history
  • Loading branch information
urbim committed Feb 5, 2021
1 parent c360937 commit 37606fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public class CustomerResource {
Exceptions can be thrown during query/mutation execution. The response will have the structure of the GraphQL error as
defined in the GraphQL specification.

By default, all messages from unchecked exceptions will be hidden for security reasons. You can override this behavior
By default, all messages from unchecked exceptions (except some defaults, see below) will be hidden for security reasons. You can override this behavior
with the configuration key `kumuluzee.graphql.exceptions.show-error-message`. The message will be replaced with
`Server Error` and can be set using the configuration key `kumuluzee.graphql.exceptions.default-error-message`.
By default, all messages from checked exceptions will be shown. You can hide messages from exceptions with the
Expand All @@ -211,6 +211,26 @@ kumuluzee:
default-error-message: Server error, for more information contact ustomer service.
```
#### `show-error-message` defaults

To provide a more seamless integration with __kumuluzee-rest__, some exceptions are added to `show-error-message`
list by default, namely:

- com.kumuluz.ee.rest.exceptions.InvalidEntityFieldException
- com.kumuluz.ee.rest.exceptions.InvalidFieldValueException
- com.kumuluz.ee.rest.exceptions.NoGenericTypeException
- com.kumuluz.ee.rest.exceptions.NoSuchEntityFieldException
- com.kumuluz.ee.rest.exceptions.QueryFormatException

To disable these defaults and handle everything manually use the following configuration:

```yaml
kumuluzee:
graphql:
exceptions:
include-show-error-defaults: false
```

## Querying GraphQL endpoint

GraphQL endpoint (`/graphql`) should be queried using a POST request. Request body should be a JSON object containing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public class KumuluzConfigMapper implements ConfigurationSource {

private static final Map<String, String> CONFIG_MAP = new HashMap<>();
private static final Map<String, String> CONFIG_MAP_LIST = new HashMap<>();
private static final String SHOW_ERROR_DEFAULTS_CONFIG_KEY =
"kumuluzee.graphql.exceptions.include-show-error-defaults";
private static final String[] SHOW_ERROR_DEFAULTS = new String[] {
"com.kumuluz.ee.rest.exceptions.InvalidEntityFieldException",
"com.kumuluz.ee.rest.exceptions.InvalidFieldValueException",
"com.kumuluz.ee.rest.exceptions.NoGenericTypeException",
"com.kumuluz.ee.rest.exceptions.NoSuchEntityFieldException",
"com.kumuluz.ee.rest.exceptions.QueryFormatException",
};

static {
CONFIG_MAP.put(ConfigKey.DEFAULT_ERROR_MESSAGE, "kumuluzee.graphql.exceptions.default-error-message");
Expand Down Expand Up @@ -81,7 +90,16 @@ public Optional<String> get(String s) {
mappedKey = CONFIG_MAP_LIST.get(s);

if (mappedKey != null) {
return configurationUtil.getList(mappedKey).map(ls -> String.join(",", ls));
Optional<String> returnValue = configurationUtil.getList(mappedKey).map(ls -> String.join(",", ls));

if ("kumuluzee.graphql.exceptions.show-error-message".equals(mappedKey) &&
configurationUtil.getBoolean(SHOW_ERROR_DEFAULTS_CONFIG_KEY).orElse(true)) {

String defaults = String.join(",", SHOW_ERROR_DEFAULTS);
returnValue = Optional.of(defaults + returnValue.map(v -> "," + v).orElse(""));
}

return returnValue;
}

return Optional.empty();
Expand Down

0 comments on commit 37606fe

Please sign in to comment.