[DEV] update models
This commit is contained in:
parent
d35c83fcbf
commit
5acdbfb0c7
@ -3,19 +3,21 @@ package org.kar.archidata.catcher;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.kar.archidata.tools.UuidUtils;
|
||||||
|
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
public class RestErrorResponse {
|
public class RestErrorResponse {
|
||||||
public UUID uuid = UUID.randomUUID();
|
public UUID uuid = UuidUtils.nextUUID();
|
||||||
|
public String name; // Mandatory for TS generic error
|
||||||
|
public String message; // Mandatory for TS generic error
|
||||||
public String time;
|
public String time;
|
||||||
public String error;
|
|
||||||
public String message;
|
|
||||||
final public int status;
|
final public int status;
|
||||||
final public String statusMessage;
|
final public String statusMessage;
|
||||||
|
|
||||||
public RestErrorResponse(final Response.Status status, final String time, final String error, final String message) {
|
public RestErrorResponse(final Response.Status status, final String time, final String error, final String message) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.error = error;
|
this.name = error;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
@ -23,13 +25,15 @@ public class RestErrorResponse {
|
|||||||
|
|
||||||
public RestErrorResponse(final Response.Status status, final String error, final String message) {
|
public RestErrorResponse(final Response.Status status, final String error, final String message) {
|
||||||
this.time = Instant.now().toString();
|
this.time = Instant.now().toString();
|
||||||
this.error = error;
|
this.name = error;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestErrorResponse(final Response.Status status) {
|
public RestErrorResponse(final Response.Status status) {
|
||||||
|
this.name = "generic";
|
||||||
|
this.message = "";
|
||||||
this.time = Instant.now().toString();
|
this.time = Instant.now().toString();
|
||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
|
@ -97,7 +97,7 @@ public class DataFactoryZod {
|
|||||||
out.append("zod.enum([");
|
out.append("zod.enum([");
|
||||||
for (final Object elem : arr) {
|
for (final Object elem : arr) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out.append(", \n\t");
|
out.append(",\n\t");
|
||||||
} else {
|
} else {
|
||||||
out.append("\n\t");
|
out.append("\n\t");
|
||||||
first = false;
|
first = false;
|
||||||
@ -106,14 +106,18 @@ public class DataFactoryZod {
|
|||||||
out.append(elem.toString());
|
out.append(elem.toString());
|
||||||
out.append("'");
|
out.append("'");
|
||||||
}
|
}
|
||||||
out.append("\n\t])");
|
if (first) {
|
||||||
|
out.append("]}");
|
||||||
|
} else {
|
||||||
|
out.append("\n\t])");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
element.isEnum = true;
|
element.isEnum = true;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
out.append("{");
|
out.append("{");
|
||||||
for (final Object elem : arr) {
|
for (final Object elem : arr) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out.append(", \n\t");
|
out.append(",\n\t");
|
||||||
} else {
|
} else {
|
||||||
out.append("\n\t");
|
out.append("\n\t");
|
||||||
first = false;
|
first = false;
|
||||||
@ -123,7 +127,11 @@ public class DataFactoryZod {
|
|||||||
out.append(elem.toString());
|
out.append(elem.toString());
|
||||||
out.append("'");
|
out.append("'");
|
||||||
}
|
}
|
||||||
out.append("}");
|
if (first) {
|
||||||
|
out.append("}");
|
||||||
|
} else {
|
||||||
|
out.append(",\n\t}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
element.declaration = out.toString();
|
element.declaration = out.toString();
|
||||||
previous.addOrder(element);
|
previous.addOrder(element);
|
||||||
|
@ -5,7 +5,7 @@ import java.util.UUID;
|
|||||||
public class RESTErrorResponseExeption extends Exception {
|
public class RESTErrorResponseExeption extends Exception {
|
||||||
public UUID uuid;
|
public UUID uuid;
|
||||||
public String time;
|
public String time;
|
||||||
public String error;
|
public String name;
|
||||||
public String message;
|
public String message;
|
||||||
public int status;
|
public int status;
|
||||||
public String statusMessage;
|
public String statusMessage;
|
||||||
@ -13,16 +13,16 @@ public class RESTErrorResponseExeption extends Exception {
|
|||||||
public RESTErrorResponseExeption() {
|
public RESTErrorResponseExeption() {
|
||||||
this.uuid = null;
|
this.uuid = null;
|
||||||
this.time = null;
|
this.time = null;
|
||||||
this.error = null;
|
this.name = null;
|
||||||
this.message = null;
|
this.message = null;
|
||||||
this.status = 0;
|
this.status = 0;
|
||||||
this.statusMessage = null;
|
this.statusMessage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RESTErrorResponseExeption(final UUID uuid, final String time, final String error, final String message, final int status, final String statusMessage) {
|
public RESTErrorResponseExeption(final UUID uuid, final String time, final String name, final String message, final int status, final String statusMessage) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.error = error;
|
this.name = name;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.statusMessage = statusMessage;
|
this.statusMessage = statusMessage;
|
||||||
@ -30,7 +30,7 @@ public class RESTErrorResponseExeption extends Exception {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", error=" + this.error + ", message=" + this.message + ", status=" + this.status + ", statusMessage="
|
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", name=" + this.name + ", message=" + this.message + ", status=" + this.status + ", statusMessage="
|
||||||
+ this.statusMessage + "]";
|
+ this.statusMessage + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class RESTApi {
|
|||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
||||||
try {
|
try {
|
||||||
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
||||||
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
|
throw out;
|
||||||
} catch (final MismatchedInputException ex) {
|
} catch (final MismatchedInputException ex) {
|
||||||
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ public class RESTApi {
|
|||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
||||||
try {
|
try {
|
||||||
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
||||||
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
|
throw out;
|
||||||
} catch (final MismatchedInputException ex) {
|
} catch (final MismatchedInputException ex) {
|
||||||
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
||||||
} catch (final JsonParseException ex) {
|
} catch (final JsonParseException ex) {
|
||||||
@ -156,7 +156,7 @@ public class RESTApi {
|
|||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
||||||
try {
|
try {
|
||||||
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
||||||
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
|
throw out;
|
||||||
} catch (final MismatchedInputException ex) {
|
} catch (final MismatchedInputException ex) {
|
||||||
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ public class RESTApi {
|
|||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
||||||
try {
|
try {
|
||||||
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
|
||||||
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
|
throw out;
|
||||||
} catch (final MismatchedInputException ex) {
|
} catch (final MismatchedInputException ex) {
|
||||||
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
|
||||||
}
|
}
|
||||||
|
@ -150,12 +150,12 @@ export function RESTRequest({ restModel, restConfig, data, params, queries }: RE
|
|||||||
const contentType = response.headers.get('Content-Type');
|
const contentType = response.headers.get('Content-Type');
|
||||||
if (restModel.accept !== contentType) {
|
if (restModel.accept !== contentType) {
|
||||||
reject({
|
reject({
|
||||||
|
name: `REST check wrong type: ${restModel.accept} != ${contentType}`,
|
||||||
|
message: "rest-tools.ts Wrong type in the message return type",
|
||||||
time: Date().toString(),
|
time: Date().toString(),
|
||||||
status: 901,
|
status: 901,
|
||||||
error: `REST check wrong type: ${restModel.accept} != ${contentType}`,
|
|
||||||
statusMessage: "Fetch error",
|
statusMessage: "Fetch error",
|
||||||
message: "rest-tools.ts Wrong type in the message return type"
|
});
|
||||||
} as RestErrorResponse);
|
|
||||||
} else if (contentType === HTTPMimeType.JSON) {
|
} else if (contentType === HTTPMimeType.JSON) {
|
||||||
response
|
response
|
||||||
.json()
|
.json()
|
||||||
@ -165,32 +165,32 @@ export function RESTRequest({ restModel, restConfig, data, params, queries }: RE
|
|||||||
})
|
})
|
||||||
.catch((reason: any) => {
|
.catch((reason: any) => {
|
||||||
reject({
|
reject({
|
||||||
|
name: `REST parse json fail: ${reason}`,
|
||||||
|
message: "rest-tools.ts Wrong message model to parse",
|
||||||
time: Date().toString(),
|
time: Date().toString(),
|
||||||
status: 902,
|
status: 902,
|
||||||
error: `REST parse json fail: ${reason}`,
|
|
||||||
statusMessage: "Fetch parse error",
|
statusMessage: "Fetch parse error",
|
||||||
message: "rest-tools.ts Wrong message model to parse"
|
});
|
||||||
} as RestErrorResponse);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
resolve({ status: response.status, data: response.body });
|
resolve({ status: response.status, data: response.body });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject({
|
reject({
|
||||||
|
name: `${response.body}`,
|
||||||
|
message: "rest-tools.ts Wrong return code",
|
||||||
time: Date().toString(),
|
time: Date().toString(),
|
||||||
status: response.status,
|
status: response.status,
|
||||||
error: `${response.body}`,
|
|
||||||
statusMessage: "Fetch code error",
|
statusMessage: "Fetch code error",
|
||||||
message: "rest-tools.ts Wrong return code"
|
});
|
||||||
} as RestErrorResponse);
|
|
||||||
}
|
}
|
||||||
}).catch((error: any) => {
|
}).catch((error: any) => {
|
||||||
reject({
|
reject({
|
||||||
|
name: error,
|
||||||
|
message: "http-wrapper.ts detect an error in the fetch request",
|
||||||
time: Date(),
|
time: Date(),
|
||||||
status: 999,
|
status: 999,
|
||||||
error: error,
|
statusMessage: "Fetch catch error"
|
||||||
statusMessage: "Fetch catch error",
|
|
||||||
message: "http-wrapper.ts detect an error in the fetch request"
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -203,12 +203,12 @@ export function RESTRequestJson<TYPE>(request: RESTRequestType, checker: (data:
|
|||||||
resolve(value.data);
|
resolve(value.data);
|
||||||
} else {
|
} else {
|
||||||
reject({
|
reject({
|
||||||
|
name: "REST Fail to verify the data",
|
||||||
|
message: "api.ts Check type as fail",
|
||||||
time: Date().toString(),
|
time: Date().toString(),
|
||||||
status: 950,
|
status: 950,
|
||||||
error: "REST Fail to verify the data",
|
|
||||||
statusMessage: "API cast ERROR",
|
statusMessage: "API cast ERROR",
|
||||||
message: "api.ts Check type as fail"
|
});
|
||||||
} as RestErrorResponse);
|
|
||||||
}
|
}
|
||||||
}).catch((reason: RestErrorResponse) => {
|
}).catch((reason: RestErrorResponse) => {
|
||||||
reject(reason);
|
reject(reason);
|
||||||
@ -222,12 +222,12 @@ export function RESTRequestJsonArray<TYPE>(request: RESTRequestType, checker: (d
|
|||||||
resolve(value.data);
|
resolve(value.data);
|
||||||
} else {
|
} else {
|
||||||
reject({
|
reject({
|
||||||
|
name: "REST Fail to verify the data",
|
||||||
|
message: "api.ts Check type as fail",
|
||||||
time: Date().toString(),
|
time: Date().toString(),
|
||||||
status: 950,
|
status: 950,
|
||||||
error: "REST Fail to verify the data",
|
|
||||||
statusMessage: "API cast ERROR",
|
statusMessage: "API cast ERROR",
|
||||||
message: "api.ts Check type as fail"
|
});
|
||||||
} as RestErrorResponse);
|
|
||||||
}
|
}
|
||||||
}).catch((reason: RestErrorResponse) => {
|
}).catch((reason: RestErrorResponse) => {
|
||||||
reject(reason);
|
reject(reason);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user