Handle the MeaningCloud status code from requests Error Codes: https://www.meaningcloud.com/developer/documentation/error-codes :return: Boolean indicating the state of request
(request)
| 459 | |
| 460 | |
| 461 | def lift_meaningcloud_request(request): |
| 462 | """ |
| 463 | Handle the MeaningCloud status code from requests |
| 464 | Error Codes: |
| 465 | https://www.meaningcloud.com/developer/documentation/error-codes |
| 466 | |
| 467 | :return: |
| 468 | Boolean indicating the state of request |
| 469 | """ |
| 470 | |
| 471 | status_code = request.getStatusCode() |
| 472 | logger = Settings.logger |
| 473 | |
| 474 | # handle per status code |
| 475 | if status_code == "0": |
| 476 | # request is successful |
| 477 | return True |
| 478 | |
| 479 | elif status_code in ["100", "101", "102"]: |
| 480 | # turn off MeaningCloud service |
| 481 | MEANINGCLOUD_CONFIG.update(enabled=False) |
| 482 | service_turnoff_msg = "turned off MeaningCloud service" |
| 483 | |
| 484 | if status_code == "100": |
| 485 | error_msg = ( |
| 486 | "operation denied: license key is either incorrect," |
| 487 | " unauthorized to make requests or you've been " |
| 488 | "banned from using service" |
| 489 | ) |
| 490 | |
| 491 | elif status_code == "101": |
| 492 | error_msg = ( |
| 493 | "license expired: license key you're sending to use " |
| 494 | "the API has expired" |
| 495 | ) |
| 496 | |
| 497 | elif status_code == "102": |
| 498 | consumed_credits = request.getConsumedCredits() or "unknown" |
| 499 | time_until_next_month = get_time_until_next_month() |
| 500 | |
| 501 | error_msg = ( |
| 502 | "credits per subscription exceeded: ran out of credits for " |
| 503 | "current month" |
| 504 | " (spent: {}) - wait for credits to be reset at month end ({}" |
| 505 | " days)".format( |
| 506 | consumed_credits, |
| 507 | truncate_float(time_until_next_month / 60 / 60 / 24, 2), |
| 508 | ) |
| 509 | ) |
| 510 | |
| 511 | print("") |
| 512 | logger.error( |
| 513 | "{}\t~{} [{}]\n".format( |
| 514 | MEANINGCLOUD_FAILURE_MSG, error_msg, service_turnoff_msg |
| 515 | ) |
| 516 | ) |
| 517 | |
| 518 | elif status_code in [ |
no test coverage detected