diff --git a/app/dao/jobs_dao.py b/app/dao/jobs_dao.py index d47aefca5..7cdca7da7 100644 --- a/app/dao/jobs_dao.py +++ b/app/dao/jobs_dao.py @@ -170,20 +170,20 @@ def dao_cancel_letter_job(job): def can_letter_job_be_cancelled(job): template = dao_get_template_by_id(job.template_id) if template.template_type != LETTER_TYPE: - return "Only letter jobs can be cancelled through this endpoint. This is not a letter job." + return False, "Only letter jobs can be cancelled through this endpoint. This is not a letter job." notifications = Notification.query.filter( Notification.job_id == job.id ).all() count_notifications = len(notifications) if job.job_status != JOB_STATUS_FINISHED or count_notifications != job.notification_count: - return "This job is still being processed. Wait a couple of minutes and try again." + return False, "This job is still being processed. Wait a couple of minutes and try again." count_cancellable_notifications = len([ n for n in notifications if n.status in CANCELLABLE_JOB_LETTER_STATUSES ]) if count_cancellable_notifications != job.notification_count or not letter_can_be_cancelled( NOTIFICATION_CREATED, job.created_at ): - return "Sorry, it's too late, letters have already been sent." + return False, "Sorry, it's too late, letters have already been sent." - return True + return True, None diff --git a/app/job/rest.py b/app/job/rest.py index 112da1459..145f3c004 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -66,12 +66,12 @@ def cancel_job(service_id, job_id): @job_blueprint.route('//cancel-letter-job', methods=['POST']) def cancel_letter_job(service_id, job_id): job = dao_get_job_by_service_id_and_job_id(service_id, job_id) - can_we_cancel = can_letter_job_be_cancelled(job) - if can_we_cancel is True: + can_we_cancel, errors = can_letter_job_be_cancelled(job) + if can_we_cancel: data = dao_cancel_letter_job(job) return jsonify(data), 200 else: - return jsonify(message=can_we_cancel), 400 + return jsonify(message=errors), 400 @job_blueprint.route('//notifications', methods=['GET'])