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
;
11 * The error code of Conversion service.
14 public enum ConversionErrorCode
{
15 /** Communication to backend service timed-out. */
18 /** Transient error while accessing the backend, please try again later. */
21 /** Something wrong in the backend that can't be sent back to application. */
24 /** Unsupported conversion attempted. */
25 UNSUPPORTED_CONVERSION
,
27 /** Conversion too large. */
30 /** Too many conversions in one request. */
33 /** Request not formed properly. */
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
)
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
)
58 private static final Logger logger
= Logger
.getLogger(
59 ConversionErrorCode
.class.getName());
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
);
70 logger
.warning(String
.format("Error code %d is undefined.", number
));
71 return INTERNAL_ERROR
;
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
);