Skip to content

Commit

Permalink
fix: handle missing address information & error messages (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-nuts authored Aug 25, 2021
1 parent b9a268d commit f13b0e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
18 changes: 5 additions & 13 deletions iris-client-fe/src/utils/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@ export const parseError = (error: AxiosError): ParsedError => {

const parseErrorMessage = (error: unknown, keys: string[]): ErrorMessage => {
if (typeof error === "object") {
const e = error as Record<string, unknown>;
const message = keys
.map((k) => e[k])
.filter((v) => typeof v === "string" && v.length > 0);
if (message.length > 0) {
return message.join(", ");
}
// return Object.keys(e)
// .map((key) => {
// return parseErrorMessage(e[key], keys);
// })
// .filter((v) => !_isNil(v))
// .join(", ");
const e = error as Record<string, string>;
const errorKey = keys.find((k) => {
return Object.prototype.hasOwnProperty.call(e, k);
});
if (errorKey) return e[errorKey];
}
if (typeof error === "string") return error;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,22 @@ import {
getStringParamFromRouteWithOptionalFallback,
} from "@/utils/pagination";
import { Dictionary } from "vue-router/types/router";
import { join } from "@/utils/misc";
function getFormattedAddress(
data?: ExistingDataRequestClientWithLocation
): string {
if (data) {
if (data.locationInformation) {
const contact = data.locationInformation.contact;
if (contact) {
let name = `${data.locationInformation.name}`;
if (contact.officialName) {
name = name + `\n(${contact.officialName})`;
}
return (
name +
`\n${contact.address.street} \n${contact.address.zip} ${contact.address.city}`
);
}
return data.locationInformation.name;
}
return "-";
}
return "-";
const contact = data?.locationInformation?.contact;
const officialName = contact?.officialName;
return join(
[
data?.locationInformation?.name ?? "-",
officialName ? `(${officialName})` : "",
contact?.address?.street,
join([contact?.address?.zip, contact?.address?.city], " "),
],
"\n"
);
}
function getFormattedDate(date?: string): string {
Expand Down Expand Up @@ -223,20 +216,26 @@ export default class EventTrackingListView extends Vue {
page: getPageFromRouteWithDefault(this.$route),
itemsPerPage: getPageSizeFromRouteWithDefault(this.$route),
loading: eventTrackingListLoading,
itemsLength: eventTrackingList?.totalElements | 0,
data: eventTrackingList?.content.map((dataRequest) => {
return {
address: getFormattedAddress(dataRequest),
endTime: getFormattedDate(dataRequest.end),
startTime: getFormattedDate(dataRequest.start),
generatedTime: getFormattedDate(dataRequest.requestedAt),
lastChange: getFormattedDate(dataRequest.lastUpdatedAt),
extID: dataRequest.externalRequestId || "-",
code: dataRequest.code,
name: dataRequest.name || "-",
status: dataRequest.status?.toString() || "-",
};
}),
itemsLength: eventTrackingList?.totalElements || 0,
data: (eventTrackingList?.content || []).map(
(
dataRequest:
| Partial<ExistingDataRequestClientWithLocation>
| undefined
) => {
return {
address: getFormattedAddress(dataRequest),
endTime: getFormattedDate(dataRequest?.end),
startTime: getFormattedDate(dataRequest?.start),
generatedTime: getFormattedDate(dataRequest?.requestedAt),
lastChange: getFormattedDate(dataRequest?.lastUpdatedAt),
extID: dataRequest?.externalRequestId || "-",
code: dataRequest?.code,
name: dataRequest?.name || "-",
status: dataRequest?.status?.toString() || "-",
};
}
),
headers: [
{
text: "Ext.ID",
Expand Down

0 comments on commit f13b0e2

Please sign in to comment.