/*
 * Copyright (C) 2016 Index Data
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package okapi.common;

import okapi.common.ErrorType;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.RoutingContext;

public class HttpResponse {
  private static Logger logger = LoggerFactory.getLogger("okapi");

  static public void responseError(RoutingContext ctx, ErrorType t, Throwable cause) {
    int code = 500;
    switch (t) {
      case OK: code = 200; break;
      case INTERNAL: code = 500; break;
      case USER: code = 400; break;
      case NOT_FOUND: code = 404; break;
      case ANY: code = 500; break;
    }
    responseError(ctx, code, cause);
  }

  static public void responseError(RoutingContext ctx, int code, Throwable cause) {
    responseError(ctx, code, cause.getMessage());
  }

  static public void responseError(RoutingContext ctx, int code, String msg) {
    if (code < 200 || code >= 300) {
      logger.error("HTTP response code=" + code + " msg=" + msg);
    }
    responseText(ctx, code).end(msg);
  }

  static public HttpServerResponse responseText(RoutingContext ctx, int code) {
    return ctx.response()
            .setStatusCode(code)
            .putHeader("Content-Type", "text/plain");
  }

  static public HttpServerResponse responseJson(RoutingContext ctx, int code) {
    return ctx.response()
            .setStatusCode(code)
            .putHeader("Content-Type", "application/json");
  }
}

@@ -618,39 +618,8 @@
 n;%0A%0A
-import okapi.common.ErrorType;%0A
 impo
@@ -660,16 +660,16 @@
 sponse;%0A
+
 import i
@@ -810,16 +810,17 @@
 ponse %7B%0A
+%0A
   privat
@@ -821,16 +821,22 @@
 private 
+final 
 static L
@@ -1023,16 +1023,24 @@
 case OK:
+%0A       
  code = 
@@ -1043,16 +1043,24 @@
 e = 200;
+%0A       
  break;%0A
@@ -1079,16 +1079,24 @@
 NTERNAL:
+%0A       
  code = 
@@ -1091,32 +1091,40 @@
      code = 500;
+%0A       
  break;%0A      ca
@@ -1131,16 +1131,24 @@
 se USER:
+%0A       
  code = 
@@ -1151,16 +1151,24 @@
 e = 400;
+%0A       
  break;%0A
@@ -1188,16 +1188,24 @@
 T_FOUND:
+%0A       
  code = 
@@ -1208,16 +1208,24 @@
 e = 404;
+%0A       
  break;%0A
@@ -1239,16 +1239,24 @@
 ase ANY:
+%0A       
  code = 
@@ -1259,16 +1259,24 @@
 e = 500;
+%0A       
  break;%0A

Reformat and remove unused import