Lines
87.50%
14 / 16
Methods
50.00%
1 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| get | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 2 | ||
| getHighestStatusCode | 75.00% | 6 / 8 | 0.00% | 0 / 1 | 6.56 | ||
| 7 | class ErrorMessages | |
| 8 | { | |
| 9 | private const int HTTP_OK = 200; | |
| 10 | private const int HTTP_BAD_REQUEST = 400; | |
| 11 | private const int HTTP_FORBIDDEN = 403; | |
| 12 | private const int HTTP_NOT_FOUND = 404; | |
| 13 | private const int HTTP_INVALID_REQUEST_METHOD = 405; | |
| 14 | private const int HTTP_NOT_ACCEPTABLE = 406; | |
| 15 | private const int HTTP_CONFLICT = 409; | |
| 16 | private const int HTTP_REQUEST_ENTITY_TOO_LARGE = 413; | |
| 17 | private const int HTTP_TOO_MANY_REQUESTS = 429; | |
| 18 | private const int HTTP_INTERNAL_SERVER_ERROR = 500; | |
| 19 | private const int HTTP_NOT_IMPLEMENTED = 501; | |
| 20 | private const int HTTP_UNAVAILABLE = 503; | |
| 21 | private const int HTTP_UNKNOWN = 520; | |
| 22 | ||
| 23 | // English messages only | |
| 24 | private const array MESSAGES = [ | |
| 25 | 'zmsClientCommunicationError' => [ | |
| 26 | 'errorCode' => 'zmsClientCommunicationError', | |
| 27 | 'errorMessage' => 'The service is temporarily unavailable. Please try again later.', | |
| 28 | 'statusCode' => self::HTTP_UNAVAILABLE, | |
| 29 | 'errorType' => 'error' | |
| 30 | ], | |
| 31 | 'notImplemented' => [ | |
| 32 | 'errorCode' => 'notImplemented', | |
| 33 | 'errorMessage' => 'Feature not implemented yet.', | |
| 34 | 'statusCode' => self::HTTP_NOT_IMPLEMENTED, | |
| 35 | 'errorType' => 'error' | |
| 36 | ], | |
| 37 | 'notFound' => [ | |
| 38 | 'errorCode' => 'notFound', | |
| 39 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 40 | 'errorMessage' => 'Endpoint not found.', | |
| 41 | 'errorType' => 'error' | |
| 42 | ], | |
| 43 | 'invalidRequest' => [ | |
| 44 | 'errorCode' => 'invalidRequest', | |
| 45 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 46 | 'errorMessage' => 'Invalid request.', | |
| 47 | 'errorType' => 'warning' | |
| 48 | ], | |
| 49 | 'requestMethodNotAllowed' => [ | |
| 50 | 'errorCode' => 'requestMethodNotAllowed', | |
| 51 | 'statusCode' => self::HTTP_INVALID_REQUEST_METHOD, | |
| 52 | 'errorMessage' => 'Request method not allowed.', | |
| 53 | 'errorType' => 'warning' | |
| 54 | ], | |
| 55 | 'captchaVerificationFailed' => [ | |
| 56 | 'errorCode' => 'captchaVerificationFailed', | |
| 57 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 58 | 'errorMessage' => 'Captcha verification failed.', | |
| 59 | 'errorType' => 'error' | |
| 60 | ], | |
| 61 | 'invalidLocationAndServiceCombination' => [ | |
| 62 | 'errorCode' => 'invalidLocationAndServiceCombination', | |
| 63 | 'errorMessage' => 'The provided service(s) do not exist at the given location.', | |
| 64 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 65 | 'errorType' => 'warning' | |
| 66 | ], | |
| 67 | 'invalidStartDate' => [ | |
| 68 | 'errorCode' => 'invalidStartDate', | |
| 69 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 70 | 'errorMessage' => 'startDate is required and must be a valid date.', | |
| 71 | 'errorType' => 'warning' | |
| 72 | ], | |
| 73 | 'invalidEndDate' => [ | |
| 74 | 'errorCode' => 'invalidEndDate', | |
| 75 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 76 | 'errorMessage' => 'endDate is required and must be a valid date.', | |
| 77 | 'errorType' => 'warning' | |
| 78 | ], | |
| 79 | 'invalidSlotsStartDate' => [ | |
| 80 | 'errorCode' => 'invalidSlotsStartDate', | |
| 81 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 82 | 'errorMessage' => 'slotsStartDate must be a valid date.', | |
| 83 | 'errorType' => 'warning' | |
| 84 | ], | |
| 85 | 'invalidSlotsEndDate' => [ | |
| 86 | 'errorCode' => 'invalidSlotsEndDate', | |
| 87 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 88 | 'errorMessage' => 'slotsEndDate must be a valid date.', | |
| 89 | 'errorType' => 'warning' | |
| 90 | ], | |
| 91 | 'slotsStartDateAfterEndDate' => [ | |
| 92 | 'errorCode' => 'slotsStartDateAfterEndDate', | |
| 93 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 94 | 'errorMessage' => 'slotsStartDate must not be after slotsEndDate.', | |
| 95 | 'errorType' => 'warning' | |
| 96 | ], | |
| 97 | 'invalidOfficeId' => [ | |
| 98 | 'errorCode' => 'invalidOfficeId', | |
| 99 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 100 | 'errorType' => 'warning', | |
| 101 | 'errorMessage' => 'officeId should be a 32-bit integer.' | |
| 102 | ], | |
| 103 | 'invalidServiceId' => [ | |
| 104 | 'errorCode' => 'invalidServiceId', | |
| 105 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 106 | 'errorType' => 'warning', | |
| 107 | 'errorMessage' => 'serviceId should be a 32-bit integer.' | |
| 108 | ], | |
| 109 | 'emptyServiceArrays' => [ | |
| 110 | 'errorCode' => 'EMPTY_SERVICE_ARRAYS', | |
| 111 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 112 | 'errorMessage' => 'Service IDs and counts cannot be empty.', | |
| 113 | 'errorType' => 'warning' | |
| 114 | ], | |
| 115 | 'mismatchedArrays' => [ | |
| 116 | 'errorCode' => 'MISMATCHED_ARRAYS', | |
| 117 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 118 | 'errorMessage' => 'Service IDs and counts must have same length.', | |
| 119 | 'errorType' => 'warning' | |
| 120 | ], | |
| 121 | 'invalidServiceCount' => [ | |
| 122 | 'errorCode' => 'invalidServiceCount', | |
| 123 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 124 | 'errorType' => 'warning', | |
| 125 | 'errorMessage' => 'serviceCounts should be an array of numeric values.' | |
| 126 | ], | |
| 127 | 'invalidProcessId' => [ | |
| 128 | 'errorCode' => 'invalidProcessId', | |
| 129 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 130 | 'errorType' => 'warning', | |
| 131 | 'errorMessage' => 'processId should be a positive 32-bit integer.' | |
| 132 | ], | |
| 133 | 'invalidScopeId' => [ | |
| 134 | 'errorCode' => 'invalidScopeId', | |
| 135 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 136 | 'errorType' => 'warning', | |
| 137 | 'errorMessage' => 'scopeId should be a positive 32-bit integer.' | |
| 138 | ], | |
| 139 | 'invalidAuthKey' => [ | |
| 140 | 'errorCode' => 'invalidAuthKey', | |
| 141 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 142 | 'errorType' => 'warning', | |
| 143 | 'errorMessage' => 'authKey should be a string.' | |
| 144 | ], | |
| 145 | 'invalidDate' => [ | |
| 146 | 'errorCode' => 'invalidDate', | |
| 147 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 148 | 'errorType' => 'warning', | |
| 149 | 'errorMessage' => 'date is required and must be a valid date.' | |
| 150 | ], | |
| 151 | 'invalidTimestamp' => [ | |
| 152 | 'errorCode' => 'invalidTimestamp', | |
| 153 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 154 | 'errorType' => 'warning', | |
| 155 | 'errorMessage' => 'Missing timestamp or invalid timestamp format. It should be a positive numeric value.' | |
| 156 | ], | |
| 157 | 'invalidFamilyName' => [ | |
| 158 | 'errorCode' => 'invalidFamilyName', | |
| 159 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 160 | 'errorType' => 'warning', | |
| 161 | 'errorMessage' => 'familyName should be a non-empty string.' | |
| 162 | ], | |
| 163 | 'invalidEmail' => [ | |
| 164 | 'errorCode' => 'invalidEmail', | |
| 165 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 166 | 'errorType' => 'warning', | |
| 167 | 'errorMessage' => 'email should be a valid email address.' | |
| 168 | ], | |
| 169 | 'invalidTelephone' => [ | |
| 170 | 'errorCode' => 'invalidTelephone', | |
| 171 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 172 | 'errorType' => 'warning', | |
| 173 | 'errorMessage' => 'telephone should be a numeric string between 7 and 15 digits.' | |
| 174 | ], | |
| 175 | 'invalidCustomTextfield' => [ | |
| 176 | 'errorCode' => 'invalidCustomTextfield', | |
| 177 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 178 | 'errorType' => 'warning', | |
| 179 | 'errorMessage' => 'customTextfield must be non-empty when required and at most 250 characters after normalization.' | |
| 180 | ], | |
| 181 | 'invalidCustomTextfield2' => [ | |
| 182 | 'errorCode' => 'invalidCustomTextfield2', | |
| 183 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 184 | 'errorType' => 'warning', | |
| 185 | 'errorMessage' => 'customTextfield2 must be non-empty when required and at most 250 characters after normalization.' | |
| 186 | ], | |
| 187 | 'familyNameCannotBeChanged' => [ | |
| 188 | 'errorCode' => 'familyNameCannotBeChanged', | |
| 189 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 190 | 'errorType' => 'warning', | |
| 191 | 'errorMessage' => 'familyName is already stored on this appointment and cannot be changed.' | |
| 192 | ], | |
| 193 | 'emailCannotBeChanged' => [ | |
| 194 | 'errorCode' => 'emailCannotBeChanged', | |
| 195 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 196 | 'errorType' => 'warning', | |
| 197 | 'errorMessage' => 'email is already stored on this appointment and cannot be changed.' | |
| 198 | ], | |
| 199 | 'telephoneCannotBeChanged' => [ | |
| 200 | 'errorCode' => 'telephoneCannotBeChanged', | |
| 201 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 202 | 'errorType' => 'warning', | |
| 203 | 'errorMessage' => 'telephone is already stored on this appointment and cannot be changed.' | |
| 204 | ], | |
| 205 | 'customTextfieldCannotBeChanged' => [ | |
| 206 | 'errorCode' => 'customTextfieldCannotBeChanged', | |
| 207 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 208 | 'errorType' => 'warning', | |
| 209 | 'errorMessage' => 'customTextfield is already stored on this appointment and cannot be changed.' | |
| 210 | ], | |
| 211 | 'customTextfield2CannotBeChanged' => [ | |
| 212 | 'errorCode' => 'customTextfield2CannotBeChanged', | |
| 213 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 214 | 'errorType' => 'warning', | |
| 215 | 'errorMessage' => 'customTextfield2 is already stored on this appointment and cannot be changed.' | |
| 216 | ], | |
| 217 | 'appointmentCanNotBeCanceled' => [ | |
| 218 | 'errorCode' => 'appointmentCanNotBeCanceled', | |
| 219 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 220 | 'errorType' => 'warning', | |
| 221 | 'errorMessage' => 'The selected appointment cannot be canceled.' | |
| 222 | ], | |
| 223 | 'appointmentNotAvailable' => [ | |
| 224 | 'errorCode' => 'appointmentNotAvailable', | |
| 225 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 226 | 'errorMessage' => 'The selected appointment is unfortunately no longer available.', | |
| 227 | 'errorType' => 'error' | |
| 228 | ], | |
| 229 | 'noAppointmentForThisDay' => [ | |
| 230 | 'errorCode' => 'noAppointmentForThisDay', | |
| 231 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 232 | 'errorMessage' => 'No available days found for the given criteria.', | |
| 233 | 'errorType' => 'info' | |
| 234 | ], | |
| 235 | 'captchaVerificationError' => [ | |
| 236 | 'errorCode' => 'captchaVerificationError', | |
| 237 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 238 | 'errorType' => 'error', | |
| 239 | 'errorMessage' => 'An error occurred during captcha verification.' | |
| 240 | ], | |
| 241 | 'captchaMissing' => [ | |
| 242 | 'errorCode' => 'captchaMissing', | |
| 243 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 244 | 'errorType' => 'error', | |
| 245 | 'errorMessage' => 'Missing captcha token.', | |
| 246 | ], | |
| 247 | 'captchaInvalid' => [ | |
| 248 | 'errorCode' => 'captchaInvalid', | |
| 249 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 250 | 'errorType' => 'error', | |
| 251 | 'errorMessage' => 'Invalid captcha token.', | |
| 252 | ], | |
| 253 | 'captchaExpired' => [ | |
| 254 | 'errorCode' => 'captchaExpired', | |
| 255 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 256 | 'errorType' => 'error', | |
| 257 | 'errorMessage' => 'Captcha token expired.', | |
| 258 | ], | |
| 259 | 'serviceUnavailable' => [ | |
| 260 | 'errorCode' => 'serviceUnavailable', | |
| 261 | 'statusCode' => self::HTTP_UNAVAILABLE, | |
| 262 | 'errorMessage' => 'Service Unavailable: The application is under maintenance.', | |
| 263 | 'errorType' => 'error' | |
| 264 | ], | |
| 265 | 'invalidSchema' => [ | |
| 266 | 'errorCode' => 'invalidSchema', | |
| 267 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 268 | 'errorType' => 'warning', | |
| 269 | 'errorMessage' => 'Data does not match the required schema.' | |
| 270 | ], | |
| 271 | ||
| 272 | //Zmsbackend exceptions | |
| 273 | 'internalError' => [ | |
| 274 | 'errorCode' => 'internalError', | |
| 275 | 'errorMessage' => 'An internal error occurred. Please try again later.', | |
| 276 | 'statusCode' => self::HTTP_INTERNAL_SERVER_ERROR, | |
| 277 | 'errorType' => 'error' | |
| 278 | ], | |
| 279 | 'invalidApiClient' => [ | |
| 280 | 'errorCode' => 'invalidApiClient', | |
| 281 | 'errorMessage' => 'Invalid API client.', | |
| 282 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 283 | 'errorType' => 'warning' | |
| 284 | ], | |
| 285 | 'sourceNotFound' => [ | |
| 286 | 'errorCode' => 'sourceNotFound', | |
| 287 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 288 | 'errorMessage' => 'Source not found.', | |
| 289 | 'errorType' => 'info' | |
| 290 | ], | |
| 291 | 'departmentNotFound' => [ | |
| 292 | 'errorCode' => 'departmentNotFound', | |
| 293 | 'errorMessage' => 'Department not found.', | |
| 294 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 295 | 'errorType' => 'error' | |
| 296 | ], | |
| 297 | 'mailNotFound' => [ | |
| 298 | 'errorCode' => 'mailNotFound', | |
| 299 | 'errorMessage' => 'Mail template not found.', | |
| 300 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 301 | 'errorType' => 'error' | |
| 302 | ], | |
| 303 | 'organisationNotFound' => [ | |
| 304 | 'errorCode' => 'organisationNotFound', | |
| 305 | 'errorMessage' => 'Organisation not found.', | |
| 306 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 307 | 'errorType' => 'error' | |
| 308 | ], | |
| 309 | 'providerNotFound' => [ | |
| 310 | 'errorCode' => 'providerNotFound', | |
| 311 | 'errorMessage' => 'Provider not found.', | |
| 312 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 313 | 'errorType' => 'error' | |
| 314 | ], | |
| 315 | 'requestNotFound' => [ | |
| 316 | 'errorCode' => 'requestNotFound', | |
| 317 | 'errorMessage' => 'Requested service not found.', | |
| 318 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 319 | 'errorType' => 'error' | |
| 320 | ], | |
| 321 | 'scopeNotFound' => [ | |
| 322 | 'errorCode' => 'scopeNotFound', | |
| 323 | 'errorMessage' => 'Scope not found.', | |
| 324 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 325 | 'errorType' => 'error' | |
| 326 | ], | |
| 327 | 'processInvalid' => [ | |
| 328 | 'errorCode' => 'processInvalid', | |
| 329 | 'errorMessage' => 'The process data is invalid.', | |
| 330 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 331 | 'errorType' => 'warning' | |
| 332 | ], | |
| 333 | 'processAlreadyExists' => [ | |
| 334 | 'errorCode' => 'processAlreadyExists', | |
| 335 | 'errorMessage' => 'An appointment process already exists.', | |
| 336 | 'statusCode' => self::HTTP_CONFLICT, | |
| 337 | 'errorType' => 'warning' | |
| 338 | ], | |
| 339 | 'processDeleteFailed' => [ | |
| 340 | 'errorCode' => 'processDeleteFailed', | |
| 341 | 'errorMessage' => 'Failed to delete the appointment.', | |
| 342 | 'statusCode' => self::HTTP_INTERNAL_SERVER_ERROR, | |
| 343 | 'errorType' => 'error' | |
| 344 | ], | |
| 345 | 'processAlreadyCalled' => [ | |
| 346 | 'errorCode' => 'processAlreadyCalled', | |
| 347 | 'errorMessage' => 'The appointment has already been called.', | |
| 348 | 'statusCode' => self::HTTP_CONFLICT, | |
| 349 | 'errorType' => 'warning' | |
| 350 | ], | |
| 351 | 'processNotReservedAnymore' => [ | |
| 352 | 'errorCode' => 'processNotReservedAnymore', | |
| 353 | 'errorMessage' => 'The appointment is no longer reserved.', | |
| 354 | 'statusCode' => self::HTTP_CONFLICT, | |
| 355 | 'errorType' => 'error' | |
| 356 | ], | |
| 357 | 'processNotPreconfirmedAnymore' => [ | |
| 358 | 'errorCode' => 'processNotPreconfirmedAnymore', | |
| 359 | 'errorMessage' => 'The appointment is no longer preconfirmed.', | |
| 360 | 'statusCode' => self::HTTP_CONFLICT, | |
| 361 | 'errorType' => 'error' | |
| 362 | ], | |
| 363 | 'emailIsRequired' => [ | |
| 364 | 'errorCode' => 'emailIsRequired', | |
| 365 | 'errorMessage' => 'Email address is required.', | |
| 366 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 367 | 'errorType' => 'warning' | |
| 368 | ], | |
| 369 | 'telephoneIsRequired' => [ | |
| 370 | 'errorCode' => 'telephoneIsRequired', | |
| 371 | 'errorMessage' => 'Telephone number is required.', | |
| 372 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 373 | 'errorType' => 'warning' | |
| 374 | ], | |
| 375 | 'appointmentNotFound' => [ | |
| 376 | 'errorCode' => 'appointmentNotFound', | |
| 377 | 'errorMessage' => 'Maybe you have already canceled your appointment? Otherwise, please check that you have used the correct link.', | |
| 378 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 379 | 'errorType' => 'error' | |
| 380 | ], | |
| 381 | 'authKeyMismatch' => [ | |
| 382 | 'errorCode' => 'authKeyMismatch', | |
| 383 | 'errorMessage' => 'Invalid authentication key.', | |
| 384 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 385 | 'errorType' => 'warning' | |
| 386 | ], | |
| 387 | 'invalidCredentials' => [ | |
| 388 | 'errorCode' => 'invalidCredentials', | |
| 389 | 'errorMessage' => 'Invalid credentials.', | |
| 390 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 391 | 'errorType' => 'warning' | |
| 392 | ], | |
| 393 | 'noAppointmentForThisScope' => [ | |
| 394 | 'errorCode' => 'noAppointmentForThisScope', | |
| 395 | 'errorMessage' => 'Please try again at a later time.', | |
| 396 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 397 | 'errorType' => 'info' | |
| 398 | ], | |
| 399 | 'tooManyAppointmentsWithSameMail' => [ | |
| 400 | 'errorCode' => 'tooManyAppointmentsWithSameMail', | |
| 401 | 'errorMessage' => 'You can only book a limited number of appointments with your e-mail address. Please cancel another appointment before you book a new one.', | |
| 402 | 'statusCode' => self::HTTP_NOT_ACCEPTABLE, | |
| 403 | 'errorType' => 'error' | |
| 404 | ], | |
| 405 | 'tooManySlotsPerAppointment' => [ | |
| 406 | 'errorCode' => 'tooManySlotsPerAppointment', | |
| 407 | 'errorMessage' => 'The number of slots exceeds the maximum allowed slots per appointment.', | |
| 408 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 409 | 'errorType' => 'error' | |
| 410 | ], | |
| 411 | 'tooManyServicesPerAppointment' => [ | |
| 412 | 'errorCode' => 'tooManyServicesPerAppointment', | |
| 413 | 'errorMessage' => 'The quantity of a service exceeds the maximum allowed quantity.', | |
| 414 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 415 | 'errorType' => 'error' | |
| 416 | ], | |
| 417 | 'scopesNotFound' => [ | |
| 418 | 'errorCode' => 'scopesNotFound', | |
| 419 | 'errorMessage' => 'No scopes found.', | |
| 420 | 'statusCode' => self::HTTP_NOT_FOUND, | |
| 421 | 'errorType' => 'error' | |
| 422 | ], | |
| 423 | 'preconfirmationExpired' => [ | |
| 424 | 'errorCode' => 'preconfirmationExpired', | |
| 425 | 'statusCode' => self::HTTP_BAD_REQUEST, | |
| 426 | 'errorMessage' => 'Unfortunately, the time for activating your appointment has expired. Please schedule the appointment again.', | |
| 427 | 'errorType' => 'error' | |
| 428 | ], | |
| 429 | 'placeholderEmailNotAllowed' => [ | |
| 430 | 'errorCode' => 'placeholderEmailNotAllowed', | |
| 431 | 'statusCode' => self::HTTP_CONFLICT, | |
| 432 | 'errorMessage' => 'The appointment cannot be confirmed until a real email address has been provided.', | |
| 433 | 'errorType' => 'error' | |
| 434 | ], | |
| 435 | ||
| 436 | //Middleware exceptions | |
| 437 | 'ipBlacklisted' => [ | |
| 438 | 'errorCode' => 'IP_BLACKLISTED', | |
| 439 | 'statusCode' => self::HTTP_FORBIDDEN, | |
| 440 | 'errorMessage' => 'Access denied - IP address is blacklisted.', | |
| 441 | 'errorType' => 'error' | |
| 442 | ], | |
| 443 | 'rateLimitExceeded' => [ | |
| 444 | 'errorCode' => 'rateLimitExceeded', | |
| 445 | 'statusCode' => self::HTTP_TOO_MANY_REQUESTS, | |
| 446 | 'errorMessage' => 'Rate limit exceeded. Please try again later.', | |
| 447 | 'errorType' => 'warning' | |
| 448 | ], | |
| 449 | 'requestEntityTooLarge' => [ | |
| 450 | 'errorCode' => 'requestEntityTooLarge', | |
| 451 | 'statusCode' => self::HTTP_REQUEST_ENTITY_TOO_LARGE, | |
| 452 | 'errorMessage' => 'Request entity too large.', | |
| 453 | 'errorType' => 'warning' | |
| 454 | ], | |
| 455 | 'securityHeaderViolation' => [ | |
| 456 | 'errorCode' => 'securityHeaderViolation', | |
| 457 | 'statusCode' => self::HTTP_FORBIDDEN, | |
| 458 | 'errorMessage' => 'Security policy violation.', | |
| 459 | 'errorType' => 'error' | |
| 460 | ], | |
| 461 | 'unauthorized' => [ | |
| 462 | 'errorCode' => 'unauthorized', | |
| 463 | 'errorMessage' => 'You are not authorized to access this resource.', | |
| 464 | 'statusCode' => self::HTTP_FORBIDDEN, | |
| 465 | 'errorType' => 'error' | |
| 466 | ], | |
| 467 | ]; | |
| 468 | ||
| 469 | /** | |
| 470 | * Get an error message by key. | |
| 471 | * | |
| 472 | * @param string $key The error message key. | |
| 473 | * @return array The error message array. | |
| 474 | */ | |
| 475 | public static function get(string $key): array | |
| 476 | { | |
| 477 | if (isset(self::MESSAGES[$key])) { | |
| 478 | return self::MESSAGES[$key]; | |
| 479 | } | |
| 480 | ||
| 481 | return [ | |
| 482 | 'errorCode' => 'unknownError', | |
| 483 | 'statusCode' => self::HTTP_UNKNOWN, | |
| 484 | 'errorMessage' => 'An unknown error occurred.', | |
| 485 | 'errorType' => 'error' | |
| 486 | ]; | |
| 487 | } | |
| 488 | ||
| 489 | /** | |
| 490 | * Get the highest status code from an array of errors. | |
| 491 | * | |
| 492 | * @param array $errors Array of error messages | |
| 493 | * @return int The highest status code found, or HTTP_OK (200) if no errors | |
| 494 | * @throws \InvalidArgumentException If any error has an invalid structure | |
| 495 | */ | |
| 496 | public static function getHighestStatusCode(array $errors): int | |
| 497 | { | |
| 498 | if (empty($errors)) { | |
| 499 | return self::HTTP_OK; | |
| 500 | } | |
| 501 | ||
| 502 | $errorCodes = []; | |
| 503 | foreach ($errors as $error) { | |
| 504 | if (!is_array($error) || !isset($error['statusCode']) || !is_int($error['statusCode'])) { | |
| 505 | throw new \InvalidArgumentException('Invalid error structure. Each error must have a statusCode.'); | |
| 506 | } | |
| 507 | $errorCodes[] = $error['statusCode']; | |
| 508 | } | |
| 509 | ||
| 510 | return max($errorCodes); | |
| 511 | } | |
| 512 | } |