19d18ec151d1e20fe7a63f46309c6b5f4a23c0ea
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / ErrorMessage.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * The contents of a {@code error-message} element as defined in
18  * <a href="https://www.rfc-editor.org/rfc/rfc8040#page-83">RFC8040 errors grouping</a>. This object can optionally
19  * transport the <a href="https://www.w3.org/TR/xml/#sec-lang-tag">Language Identification</a> as conveyed via,
20  * for example, <a href="https://www.rfc-editor.org/rfc/rfc6241#page-17">RFC6241 error-message element</a>.
21  *
22  * @param elementBody the string to be displayed
23  * @param xmlLang optional Language Identification string
24  */
25 @NonNullByDefault
26 // TODO: consider sharing this class with netconf-api's NetconfDocumentedException
27 public record ErrorMessage(String elementBody, @Nullable String xmlLang) {
28     public ErrorMessage {
29         requireNonNull(elementBody);
30     }
31
32     public ErrorMessage(final String elementBody) {
33         this(elementBody, null);
34     }
35
36     @Override
37     public String toString() {
38         return MoreObjects.toStringHelper(this).omitNullValues()
39             .add("elementBody", elementBody)
40             .add("xmlLang", xmlLang)
41             .toString();
42     }
43 }