001/*
002 *   Copyright 2024 Vonage
003 *
004 *   Licensed under the Apache License, Version 2.0 (the "License");
005 *   you may not use this file except in compliance with the License.
006 *   You may obtain a copy of the License at
007 *
008 *        http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *   Unless required by applicable law or agreed to in writing, software
011 *   distributed under the License is distributed on an "AS IS" BASIS,
012 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *   See the License for the specific language governing permissions and
014 *   limitations under the License.
015 */
016package com.vonage.client.meetings;
017
018import com.fasterxml.jackson.annotation.*;
019import com.vonage.client.VonageApiResponseException;
020
021/**
022 * Response returned when an error is encountered (i.e. the API returns a non-2xx status code).
023 */
024public final class MeetingsResponseException extends VonageApiResponseException {
025        @JsonProperty("status") private Integer status;
026        @JsonProperty("name") private String name;
027        @JsonProperty("message") private String message;
028
029        public MeetingsResponseException() {
030                super();
031        }
032
033        MeetingsResponseException(String message) {
034                super(message);
035        }
036
037        void setStatusCode(Integer status) {
038                this.status = statusCode = status;
039        }
040
041        public String getName() {
042                return name;
043        }
044
045        @JsonGetter("message")
046        @Override
047        public String getMessage() {
048                return message != null ? message : super.getMessage();
049        }
050
051        private static MeetingsResponseException setStatus(MeetingsResponseException ex) {
052                if (ex.status == null || ex.status < 100) {
053                        ex.setStatusCode(ex.statusCode);
054                }
055                else if (ex.statusCode < 100) {
056                        ex.setStatusCode(ex.status);
057                }
058                return ex;
059        }
060
061        /**
062         * Creates an instance of this class from a JSON payload.
063         *
064         * @param json The JSON string to parse.
065         * @return An instance of this class with all known fields populated from the JSON payload, if present.
066         */
067        @JsonCreator
068        public static MeetingsResponseException fromJson(String json) {
069                return setStatus(fromJson(MeetingsResponseException.class, json));
070        }
071}