Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/backend/src/apis/filters/domain-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
HttpStatus,
} from '@nestjs/common';
import { Response } from 'express';
import {
DomainError,
DomainErrorKind,
} from '../../domain/shared/domain.error';
import { DomainError, DomainErrorKind } from '../../domain/shared/domain.error';

/**
* Generic HTTP mapping for domain errors. New DomainError subclasses just need
Expand Down Expand Up @@ -36,7 +33,7 @@ export class DomainExceptionFilter implements ExceptionFilter {

response.status(status).json({
statusCode: status,
code: exception.code,
error: exception.code,
message: exception.message,
});
}
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/apis/fleet-management/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ export const releaseSuccessExample: Vehicle = {

export const vehicleOfflineErrorExample = {
statusCode: 409,
code: 'VEHICLE_OFFLINE',
error: 'VEHICLE_OFFLINE',
message: 'Only online vehicles can be taken over',
};

export const vehicleAlreadyAssignedErrorExample = {
statusCode: 409,
code: 'VEHICLE_ALREADY_ASSIGNED',
error: 'VEHICLE_ALREADY_ASSIGNED',
message: 'Another operator is holding this vehicle',
};

export const operatorAlreadyHasVehicleErrorExample = {
statusCode: 409,
code: 'OPERATOR_ALREADY_HAS_VEHICLE',
error: 'OPERATOR_ALREADY_HAS_VEHICLE',
message: 'Operator is already holding a vehicle; release it first',
};

export const vehicleNotHeldByOperatorErrorExample = {
statusCode: 409,
code: 'VEHICLE_NOT_HELD_BY_OPERATOR',
error: 'VEHICLE_NOT_HELD_BY_OPERATOR',
message: 'Operator is not holding this vehicle',
};

export const notFoundErrorExample = {
statusCode: 404,
code: 'VEHICLE_NOT_FOUND',
error: 'VEHICLE_NOT_FOUND',
message: `Vehicle ${VEHICLE_ID} not found`,
};
2 changes: 1 addition & 1 deletion apps/backend/src/apis/operators/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const operatorListExample: Operator[] = [

export const operatorNotFoundExample = {
statusCode: 404,
code: 'OPERATOR_NOT_FOUND',
error: 'OPERATOR_NOT_FOUND',
message: `Operator ${OP_ID_A} not found`,
};
4 changes: 2 additions & 2 deletions apps/backend/src/apis/vehicles/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const setConnectivityOfflineExample = { status: 'offline' as const };

export const vehicleNotFoundExample = {
statusCode: 404,
code: 'VEHICLE_NOT_FOUND',
error: 'VEHICLE_NOT_FOUND',
message: `Vehicle ${SAMPLE_VEHICLE_ID} not found`,
};

export const cannotOfflineAssignedExample = {
statusCode: 409,
code: 'CANNOT_OFFLINE_ASSIGNED_VEHICLE',
error: 'CANNOT_OFFLINE_ASSIGNED_VEHICLE',
message: 'release the vehicle first',
};
9 changes: 7 additions & 2 deletions apps/operator-dashboard/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ApiError, type ApiErrorBody, type Operator, type Vehicle } from './types';
import {
ApiError,
type ApiErrorBody,
type Operator,
type Vehicle,
} from './types';

const BASE_URL = import.meta.env.VITE_API_URL ?? 'http://localhost:3000';

Expand All @@ -17,7 +22,7 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
}
throw new ApiError(
body.message ?? `Request failed with status ${res.status}`,
body.code ?? 'UNKNOWN_ERROR',
body.error ?? 'UNKNOWN_ERROR',
res.status,
);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/operator-dashboard/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type Operator = {

export type ApiErrorBody = {
statusCode: number;
code: string;
error: string;
message: string;
};

Expand Down
Loading