Skip to content

HR API Reference

This reference covers the exception code system used by all Microtec ERP services, with special focus on HR-specific business rule violations.


Response Envelope

All API responses follow a standard envelope:

json
{
  "success": true,
  "data": { },
  "message": null,
  "messageCode": 0,
  "validationErrors": []
}

On error:

json
{
  "success": false,
  "data": null,
  "message": "Employee already has an active contract",
  "messageCode": 9017,
  "validationErrors": []
}

FluentValidation errors (code 4001)

When messageCode is 4001, check the validationErrors array for field-level messages:

json
{
  "validationErrors": [
    { "field": "StartDate", "message": "Start date is required" }
  ]
}

Code Ranges

RangeCategory
1000–1999CRM Integration Errors
3000–3999General Business Logic Errors
4000–4999Validation Errors
5000–5999System Errors
6000–6999Authentication & Authorization Errors
7000–7999Deletion Errors
8000–8999Balance / Financial Errors
9000–9999Business Rule Violations

CRM Integration Errors (1000–1999)

CodeNameDescription
1001CrmConnectionFailedFailed to connect to CRM system
1002CrmOperationFailedCRM operation failed

General Business Logic Errors (3000–3999)

CodeNameDescription
3001NotFoundThe requested resource was not found
3002CaptchaNotValidCaptcha validation failed
3003CaptchaGenerationErrorError generating captcha
3004QrGenerationErrorError generating QR code
3005AlreadyExistResource already exists (duplicate entry)
3006InvalidDataThe provided data is invalid
3007IdentityCreationFaildFailed to create user identity
3008InvalidOperationThe requested operation is invalid

Validation Errors (4000–4999)

CodeNameDescription
4001FluentValidationFluentValidation failed — check validationErrors array
4002ModelStateValidationModel state validation failed
4003XssViolationCross-site scripting (XSS) violation detected

System Errors (5000–5999)

CodeNameDescription
5001UnhandledAn unhandled exception occurred
5003UnhealthySystem is unhealthy or unavailable

Authentication & Authorization Errors (6000–6999)

CodeNameDescription
6000UnauthorizedUser is not authenticated (HTTP 401)
6001ForbiddenUser is authenticated but not authorized (HTTP 403)
6002InvalidCredentialsInvalid username or password
6003DisabledRouteThe requested route is disabled

Deletion Errors (7000–7999)

CodeNameDescription
7000DeleteFailedDelete blocked — resource has dependencies

Balance / Financial Errors (8000–8999)

CodeNameDescription
8000InvalidBalanceInvalid balance calculation or amount

Business Rule Violations (9000–9999)

Sequence & Configuration (9000–9004)

CodeNameDescription
9000NoSequenceConfigurationNo sequence configuration found for this document type
9001MaxSequenceReachedMaximum sequence number has been reached
9002CostIsZeroCost cannot be zero
9003PostedStatusRequiredRecord must be in posted status to perform this action
9004SequenceExistSequence configuration already exists

Entity Relationships (9005–9008)

CodeNameDescription
9005JobRelatedWithPositionsCannot delete job — it is linked to one or more positions
9006DepartmentRelatedWithEmployeesCannot delete department — it has employees assigned
9007DepartmentRelatedWithAnotherDepartmentCannot delete department — it is a parent of another department
9008WorklocationRelatedWithPositionsCannot delete work location — it is linked to positions

Contract Rules (9009–9018)

CodeNameDescription
9009ContractShouldHavePositionContract must have a position assigned
9010ContractShouldHaveSalaryContract must have a salary configuration
9011CantRenewDraftedContractCannot renew a contract in draft status
9012CantUpgradeDraftedContractCannot upgrade a contract in draft status
9013LastRecordEndDateExceedsContractEndDateLast record's end date exceeds the contract end date
9014StartDateCannotBeBeforeContractStartDateStart date cannot be before the contract start date
9015StartDateCannotBeAfterContractEndDateStart date cannot be after the contract end date
9016SalaryOrPositionShouldHaveValueEither salary or position must have a value
9017EmployeeAlreadyHasContractEmployee already has an active contract
9018DraftedContractOnlyCanEditOnly drafted contracts can be edited

Salary & Template Rules (9019–9021)

CodeNameDescription
9019SalaryTemplateRelatedWithContractsCannot delete salary template — it is linked to contracts
9020InvalidCalculationFormulaThe salary calculation formula is invalid
9021SalaryItemRelatedWithSalaryTemplateItemCannot delete salary item — it is linked to salary template items

Employee Rules (9022–9023)

CodeNameDescription
9022EmoployeeShouldReportToAnotherEmployeeEmployee must report to another employee (note: typo intentional in codebase)
9023EmployeeHasnotContractEmployee does not have a contract

Record Status Rules (9024–9027)

CodeNameDescription
9024CantEditOrDeletePostedRecordCannot edit or delete a posted record
9025LoanAmountExceedsLimitLoan amount exceeds the allowed limit
9026InstallmentAmountExceedsSalaryInstalment amount exceeds the employee's salary
9027RecordPostedBeforeRecord was already posted previously

Dependency & Workflow Rules (9028–9030)

CodeNameDescription
9028TheNewItemDependOnAnotherItemYouDontSelectedYetNew item depends on another item that has not been selected yet
9029EmploymentCommencementPostedEmployment commencement has already been posted
9030CantRenewClosedNotRenewableContractCannot renew a contract that is closed and not renewable

TypeScript Enum

Copy this enum into your Angular / TypeScript project for type-safe error handling:

typescript
export enum ExceptionCodes {
  // CRM Integration Errors (1000-1999)
  CrmConnectionFailed = 1001,
  CrmOperationFailed = 1002,

  // General Business Logic Errors (3000-3999)
  NotFound = 3001,
  CaptchaNotValid = 3002,
  CaptchaGenerationError = 3003,
  QrGenerationError = 3004,
  AlreadyExist = 3005,
  InvalidData = 3006,
  IdentityCreationFaild = 3007,
  InvalidOperation = 3008,

  // Validation Errors (4000-4999)
  FluentValidation = 4001,
  ModelStateValidation = 4002,
  XssViolation = 4003,

  // System Errors (5000-5999)
  Unhandled = 5001,
  Unhealthy = 5003,

  // Authentication & Authorization Errors (6000-6999)
  Unauthorized = 6000,
  Forbidden = 6001,
  InvalidCredentials = 6002,
  DisabledRoute = 6003,

  // Deletion Errors (7000-7999)
  DeleteFailed = 7000,

  // Balance/Financial Errors (8000-8999)
  InvalidBalance = 8000,

  // Business Rule Violations (9000-9999)
  // Sequence & Configuration
  NoSequenceConfiguration = 9000,
  MaxSequenceReached = 9001,
  CostIsZero = 9002,
  PostedStatusRequired = 9003,
  SequenceExist = 9004,

  // Entity Relationships
  JobRelatedWithPositions = 9005,
  DepartmentRelatedWithEmployees = 9006,
  DepartmentRelatedWithAnotherDepartment = 9007,
  WorklocationRelatedWithPositions = 9008,

  // Contract Rules
  ContractShouldHavePosition = 9009,
  ContractShouldHaveSalary = 9010,
  CantRenewDraftedContract = 9011,
  CantUpgradeDraftedContract = 9012,
  LastRecordEndDateExceedsContractEndDate = 9013,
  StartDateCannotBeBeforeContractStartDate = 9014,
  StartDateCannotBeAfterContractEndDate = 9015,
  SalaryOrPositionShouldHaveValue = 9016,
  EmployeeAlreadyHasContract = 9017,
  DraftedContractOnlyCanEdit = 9018,

  // Salary & Template Rules
  SalaryTemplateRelatedWithContracts = 9019,
  InvalidCalculationFormula = 9020,
  SalaryItemRelatedWithSalaryTemplateItem = 9021,

  // Employee Rules
  EmoployeeShouldReportToAnotherEmployee = 9022,
  EmployeeHasnotContract = 9023,

  // Record Status Rules
  CantEditOrDeletePostedRecord = 9024,
  LoanAmountExceedsLimit = 9025,
  InstallmentAmountExceedsSalary = 9026,
  RecordPostedBefore = 9027,

  // Dependency & Workflow Rules
  TheNewItemDependOnAnotherItemYouDontSelectedYet = 9028,
  EmploymentCommencementPosted = 9029,
  CantRenewClosedNotRenewableContract = 9030,
}

Usage Example

typescript
import { ExceptionCodes } from './enums/ExceptionCodes';

function handleApiError(error: ApiError): void {
  switch (error.messageCode) {
    case ExceptionCodes.NotFound:
      showError('The requested item was not found');
      break;

    case ExceptionCodes.EmployeeAlreadyHasContract:
      showError('This employee already has an active contract');
      break;

    case ExceptionCodes.FluentValidation:
      // Field-level validation — display individual field errors
      error.validationErrors?.forEach(ve => {
        setFieldError(ve.field, ve.message);
      });
      break;

    case ExceptionCodes.DeleteFailed:
      showError('Cannot delete — this record has dependencies');
      break;

    default:
      showError(error.message ?? 'An unexpected error occurred');
  }
}

Notes

  • Code 9022 (EmoployeeShouldReportToAnotherEmployee) contains a typo (Emoylee) that is intentional — it matches the server-side constant exactly. Do not correct it in the enum.
  • Codes 60006001 correspond to HTTP 401/403 respectively, but provide more specific context for UI messaging.
  • Codes 90009030 always require user action or data correction; they should never be silently swallowed.

Internal Documentation — Microtec Platform Team