Polish "Fix NPE in HttpResponseSnippet when response has custom status"

See gh-653
This commit is contained in:
Andy Wilkinson
2019-10-22 10:06:51 +01:00
parent aee641b642
commit d925a9f219
4 changed files with 15 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,17 +56,17 @@ public class HttpResponseSnippet extends TemplatedSnippet {
@Override
protected Map<String, Object> createModel(Operation operation) {
OperationResponse response = operation.getResponse();
HttpStatus status = response.getStatus();
Map<String, Object> model = new HashMap<>();
model.put("responseBody", responseBody(response));
model.put("headers", headers(response));
HttpStatus status = response.getStatus();
if (status != null) {
model.put("statusCode", status.value());
model.put("statusReason", status.getReasonPhrase());
}
else {
model.put("statusCode", response.getStatusCode());
model.put("statusReason", "Http custom status.");
model.put("statusReason", "");
}
return model;
}