Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / conversion / ConversionErrorCode.java
blob3cfa19f04771f7e2929bb20efef5097ef205d387
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.conversion;
5 import com.google.appengine.api.conversion.ConversionServicePb.ConversionServiceError.ErrorCode;
6 import com.google.common.collect.ImmutableMap;
8 import java.util.logging.Logger;
10 /**
11 * The error code of Conversion service.
14 public enum ConversionErrorCode {
15 /** Communication to backend service timed-out. */
16 TIMEOUT,
18 /** Transient error while accessing the backend, please try again later. */
19 TRANSIENT_ERROR,
21 /** Something wrong in the backend that can't be sent back to application. */
22 INTERNAL_ERROR,
24 /** Unsupported conversion attempted. */
25 UNSUPPORTED_CONVERSION,
27 /** Conversion too large. */
28 CONVERSION_TOO_LARGE,
30 /** Too many conversions in one request. */
31 TOO_MANY_CONVERSIONS,
33 /** Request not formed properly. */
34 INVALID_REQUEST;
36 static final ImmutableMap<Integer, ConversionErrorCode> INT_ENUM_MAP =
37 new ImmutableMap.Builder<Integer, ConversionErrorCode>()
38 .put(ErrorCode.TIMEOUT_VALUE, TIMEOUT)
39 .put(ErrorCode.TRANSIENT_ERROR_VALUE, TRANSIENT_ERROR)
40 .put(ErrorCode.INTERNAL_ERROR_VALUE, INTERNAL_ERROR)
41 .put(ErrorCode.UNSUPPORTED_CONVERSION_VALUE, UNSUPPORTED_CONVERSION)
42 .put(ErrorCode.CONVERSION_TOO_LARGE_VALUE, CONVERSION_TOO_LARGE)
43 .put(ErrorCode.TOO_MANY_CONVERSIONS_VALUE, TOO_MANY_CONVERSIONS)
44 .put(ErrorCode.INVALID_REQUEST_VALUE, INVALID_REQUEST)
45 .build();
47 static final ImmutableMap<ConversionErrorCode, ErrorCode> ENUM_PROTO_MAP =
48 new ImmutableMap.Builder<ConversionErrorCode, ErrorCode>()
49 .put(TIMEOUT, ErrorCode.TIMEOUT)
50 .put(TRANSIENT_ERROR, ErrorCode.TRANSIENT_ERROR)
51 .put(INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR)
52 .put(UNSUPPORTED_CONVERSION, ErrorCode.UNSUPPORTED_CONVERSION)
53 .put(CONVERSION_TOO_LARGE, ErrorCode.CONVERSION_TOO_LARGE)
54 .put(TOO_MANY_CONVERSIONS, ErrorCode.TOO_MANY_CONVERSIONS)
55 .put(INVALID_REQUEST, ErrorCode.INVALID_REQUEST)
56 .build();
58 private static final Logger logger = Logger.getLogger(
59 ConversionErrorCode.class.getName());
61 /**
62 * Maps from integer type error code to enum type error code.
64 * @param number the integer type error code
65 * @return the enum type error code
67 static ConversionErrorCode intToEnum(int number) {
68 ConversionErrorCode code = INT_ENUM_MAP.get(number);
69 if (code == null) {
70 logger.warning(String.format("Error code %d is undefined.", number));
71 return INTERNAL_ERROR;
73 return code;
76 /**
77 * Maps from enum type error code to protocol buffer error code.
79 * @param errorCode the enum type error code
80 * @return the protocol buffer error code
82 static ErrorCode enumToProto(ConversionErrorCode errorCode) {
83 return ENUM_PROTO_MAP.get(errorCode);