org.finos.legend.engine.postgres.PGError Maven / Gradle / Ivy
/*
* Licensed to Crate.io GmbH ("Crate") under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. Crate licenses
* this file to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* However, if you have executed another commercial license agreement
* with Crate these terms will supersede the license and you may use the
* software solely pursuant to the terms of the relevant commercial agreement.
*/
package org.finos.legend.engine.postgres;
import java.nio.charset.StandardCharsets;
public class PGError
{
public static final byte[] SEVERITY_FATAL = "FATAL".getBytes(StandardCharsets.UTF_8);
public static final byte[] SEVERITY_ERROR = "ERROR".getBytes(StandardCharsets.UTF_8);
private final PGErrorStatus status;
private final String message;
private final Throwable throwable;
public PGError(PGErrorStatus status, String message, Throwable throwable)
{
this.status = status;
this.message = message;
this.throwable = throwable;
}
public PGErrorStatus status()
{
return status;
}
public Throwable throwable()
{
return throwable;
}
public String message()
{
return message;
}
@Override
public String toString()
{
return "PGError{" +
"status=" + status +
", message='" + message + '\'' +
", throwable=" + throwable +
'}';
}
public static PGError fromThrowable(Throwable throwable)
{
return new PGError(PGErrorStatus.INTERNAL_ERROR, throwable.getMessage(), throwable);
/* PGErrorStatus status = PGErrorStatus.INTERNAL_ERROR;
if (throwable instanceof IllegalArgumentException || throwable instanceof UnsupportedOperationException) {
status = PGErrorStatus.FEATURE_NOT_SUPPORTED;
} else if (throwable instanceof DuplicateKeyException) {
status = PGErrorStatus.UNIQUE_VIOLATION;
} else if (throwable instanceof RelationUnknown) {
status = PGErrorStatus.UNDEFINED_TABLE;
} else if (throwable instanceof ColumnUnknownException) {
status = PGErrorStatus.UNDEFINED_COLUMN;
} else if (throwable instanceof RelationAlreadyExists) {
status = PGErrorStatus.DUPLICATE_TABLE;
} else if (throwable instanceof AmbiguousColumnException) {
status = PGErrorStatus.AMBIGUOUS_COLUMN;
} else if (throwable instanceof InvalidSchemaNameException) {
status = PGErrorStatus.INVALID_SCHEMA_NAME;
} else if (throwable instanceof AmbiguousColumnAliasException) {
status = PGErrorStatus.AMBIGUOUS_ALIAS;
} else if (throwable instanceof UserDefinedFunctionUnknownException) {
status = PGErrorStatus.UNDEFINED_FUNCTION;
}
return new PGError(status, SQLExceptions.messageOf(throwable), throwable);*/
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy