|
| 1 | +/* |
| 2 | + * Copyright 2013 Stormpath, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.stormpath.sdk.impl.error; |
| 17 | + |
| 18 | +import com.stormpath.sdk.error.Error; |
| 19 | +import com.stormpath.sdk.impl.resource.AbstractResource; |
| 20 | +import com.stormpath.sdk.impl.resource.IntegerProperty; |
| 21 | +import com.stormpath.sdk.impl.resource.ListProperty; |
| 22 | +import com.stormpath.sdk.impl.resource.Property; |
| 23 | +import com.stormpath.sdk.impl.resource.StringProperty; |
| 24 | + |
| 25 | +import java.io.Serializable; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | + |
| 29 | +/** |
| 30 | + * @since 0.1 |
| 31 | + */ |
| 32 | +public class OktaError extends AbstractResource implements Error, Serializable { |
| 33 | + |
| 34 | + static final long serialVersionUID = 42L; |
| 35 | + |
| 36 | + public static final IntegerProperty STATUS = new IntegerProperty("status"); |
| 37 | + static final StringProperty ERROR_CODE = new StringProperty("errorCode"); |
| 38 | + static final StringProperty ERROR_SUMMARY = new StringProperty("errorSummary"); |
| 39 | + static final ListProperty ERROR_CAUSES = new ListProperty("errorCauses"); |
| 40 | + static final StringProperty ERROR_ID = new StringProperty("errorId"); |
| 41 | + |
| 42 | + private static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap( |
| 43 | + STATUS, ERROR_CODE, ERROR_SUMMARY, ERROR_CAUSES, ERROR_ID |
| 44 | + ); |
| 45 | + |
| 46 | + public OktaError(Map<String, Object> body) { |
| 47 | + super(null, body); |
| 48 | + } |
| 49 | + |
| 50 | + // Needed for this class to be serializable |
| 51 | + public OktaError() { |
| 52 | + super(null, null); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public Map<String, Property> getPropertyDescriptors() { |
| 57 | + return PROPERTY_DESCRIPTORS; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public int getStatus() { |
| 62 | + return getInt(STATUS); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public int getCode() { |
| 67 | + return 0; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + @SuppressWarnings("unchecked") |
| 72 | + public String getMessage() { |
| 73 | + List causes = getListProperty(ERROR_CAUSES.getName()); |
| 74 | + return ((Map<String, String>)causes.get(0)).get("errorSummary"); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String getDeveloperMessage() { |
| 79 | + return ""; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String getMoreInfo() { |
| 84 | + return getString(ERROR_SUMMARY); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public String getRequestId() { |
| 89 | + return getString(ERROR_ID); |
| 90 | + } |
| 91 | + |
| 92 | +} |
0 commit comments