use of com.faforever.server.error.ErrorResponse in project faf-java-server by FAForever.
the class ErrorResponseTransformerTest method transform.
@Test
public void transform() throws Exception {
ErrorCode errorCode = ErrorCode.UNSUPPORTED_REQUEST;
ErrorResponse errorResponse = new ErrorResponse(errorCode, UUID.randomUUID(), new Object[] { "foobar" });
Map<String, Serializable> result = ErrorResponseTransformer.INSTANCE.transform(errorResponse);
assertThat(result.get("command"), is("notice"));
assertThat(result.get("style"), is("error"));
assertThat(result.get("code"), is(errorCode.getCode()));
assertThat(result.get("text"), is(MessageFormat.format(errorCode.getTitle() + ": " + errorCode.getDetail(), "foobar")));
}
use of com.faforever.server.error.ErrorResponse in project faf-java-server by FAForever.
the class IntegrationConfig method requestExceptionTransformer.
/**
* Transformer that transforms a {@link MessageHandlingException} into and {@link ErrorResponse}.
*/
private AbstractTransformer requestExceptionTransformer() {
return new AbstractTransformer() {
@Override
protected Object doTransform(Message<?> message) throws Exception {
MessagingException messageException = (MessagingException) message.getPayload();
Message<?> failedMessage = messageException.getFailedMessage();
// TODO try to make more intuitive? Meanwhile, look at requestExceptionFilter() to understand.
RequestException requestException;
if (messageException instanceof MessageTransformationException) {
requestException = (RequestException) messageException.getCause().getCause();
} else {
requestException = (RequestException) messageException.getCause();
}
MessageBuilder<ErrorResponse> builder = MessageBuilder.withPayload(new ErrorResponse(requestException.getErrorCode(), requestException.getRequestId(), requestException.getArgs())).copyHeaders(message.getHeaders());
builder.setHeader(CLIENT_CONNECTION, failedMessage.getHeaders().get(CLIENT_CONNECTION, ClientConnection.class));
return builder.build();
}
};
}
use of com.faforever.server.error.ErrorResponse in project faf-java-server by FAForever.
the class V2ServerMessageTransformerTest method errorMessage.
@Test
public void errorMessage() throws Exception {
UUID requestId = UUID.randomUUID();
String response = instance.transform(new ErrorResponse(ErrorCode.UNSUPPORTED_REQUEST, requestId, new String[] { "{\"foo\": \"bar\"}" }));
assertThat(response, is("{\"data\":{\"code\":109,\"title\":\"Unsupported request\",\"text\":\"The server received an unsupported request from your client: {\\\"foo\\\": \\\"bar\\\"}\",\"requestId\":\"" + requestId + "\",\"args\":[\"{\\\"foo\\\": \\\"bar\\\"}\"]},\"type\":\"error\"}"));
}
Aggregations