Skip to content

Commit

Permalink
fix: optional for possible undefined objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fhenrich33 committed Sep 4, 2024
1 parent 552bcbb commit d534537
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
18 changes: 8 additions & 10 deletions front/src/hooks/useAssignBoxesToShipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const useAssignBoxesToShipment = () => {
.then(({ data, errors }) => {
setIsLoading(false);
if ((errors?.length || 0) > 0) {
const errorCode = errors ? errors[0].extensions.code : undefined;
const errorCode = errors ? errors[0].extensions?.code : undefined;
// Example: the user is not of the sending base
if (errorCode === "FORBIDDEN") {
if (showErrors)
Expand Down Expand Up @@ -168,9 +168,8 @@ export const useAssignBoxesToShipment = () => {
if (assignedBoxes.length) {
if (showToasts)
createToast({
message: `${
assignedBoxes.length === 1 ? "A Box was" : `${assignedBoxes.length} Boxes were`
} successfully assigned to the shipment.`,
message: `${assignedBoxes.length === 1 ? "A Box was" : `${assignedBoxes.length} Boxes were`
} successfully assigned to the shipment.`,
});
}
// Not all Boxes were assigned
Expand Down Expand Up @@ -232,7 +231,7 @@ export const useAssignBoxesToShipment = () => {
.then(({ data, errors }) => {
setIsLoading(false);
if ((errors?.length || 0) > 0) {
const errorCode = errors ? errors[0].extensions.code : undefined;
const errorCode = errors ? errors[0].extensions?.code : undefined;
// Example: the user is not of the sending base
if (errorCode === "FORBIDDEN") {
if (showToastMessage)
Expand Down Expand Up @@ -290,11 +289,10 @@ export const useAssignBoxesToShipment = () => {
if (unassignedBoxes.length) {
if (showToastMessage)
createToast({
message: `${
unassignedBoxes.length === 1
? "A Box was"
: `${unassignedBoxes.length} Boxes were`
} successfully removed from the shipment.`,
message: `${unassignedBoxes.length === 1
? "A Box was"
: `${unassignedBoxes.length} Boxes were`
} successfully removed from the shipment.`,
});
}
// Not all Boxes were unassigned
Expand Down
2 changes: 1 addition & 1 deletion front/src/hooks/useLabelIdentifierResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useLabelIdentifierResolver = () => {
})
.then(({ data, errors }) => {
if ((errors?.length || 0) > 0) {
const errorCode = errors ? errors[0].extensions.code : undefined;
const errorCode = errors ? errors[0].extensions?.code : undefined;
if (errorCode === "FORBIDDEN") {
return {
kind: ILabelIdentifierResolverResultKind.NOT_AUTHORIZED,
Expand Down
2 changes: 1 addition & 1 deletion front/src/hooks/useQrResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useQrResolver = () => {
})
.then(({ data, errors }) => {
if ((errors?.length || 0) > 0) {
const errorCode = errors ? errors[0].extensions.code : undefined;
const errorCode = errors ? errors[0].extensions?.code : undefined;
if (errorCode === "FORBIDDEN") {
triggerError({
message: "You don't have permission to access this box!",
Expand Down
2 changes: 1 addition & 1 deletion front/src/views/BoxCreate/BoxCreateView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function BoxCreateView() {
})
.then((mutationResult) => {
if (mutationResult.errors) {
const errorCode = mutationResult.errors[0].extensions.code;
const errorCode = mutationResult.errors[0].extensions?.code;
if (errorCode === "BAD_USER_INPUT") {
triggerError({
message: "The QR code is already used for another box.",
Expand Down

0 comments on commit d534537

Please sign in to comment.