проанализируй и улучши данную Laravel 9 функцию, что бы учесть все возможые ошибки и сбой.     public function add_reliever()
    {
        $request = Request::all();
        $application_id = Request::get('id');
        $berth_id =Request::get('berth_id');
        $from_application = Request::get('from_application');
        $reliever = Application::find($application_id);
        $berth = Vessel_berth::where('id',$request['berth_id'])->with('vessel')->first();

        if($berth) {
	        if ($application_id and $berth_id) {
		        if ($reliever) {
			        if ($reliever->status['id'] === 4) {
				        return response()->json([
					        'status' => 'onboard',
					        'vessel_list'=>$this->from_application($from_application,4,$application_id),
					        'seafarer'=>$reliever->status
				        ], 200);
			        } elseif ($reliever->status['id'] === 2) {
				        return response()->json([
					        'status' => 'proposed',
					        'vessel_list'=>$this->from_application($from_application,2,$application_id),
					        'seafarer'=>$reliever->status
				        ], 200);
			        } elseif ($reliever->status['id'] === 3) {
				        return response()->json([
					        'status' => 'approved',
					        'vessel_list'=>$this->from_application($from_application,3,$application_id),
					        'seafarer'=>$reliever->status
				        ], 200);
			        } else {
				        DB::transaction(function () use ($reliever, $request, $berth) {
					        Vessel_reliever::Create([
						        'vessel_berth_id' => $request['berth_id'],
						        'application_id' => $request['id'],
						        'proposed_by' => Auth::id(),
						        'previous_status'=>$reliever->status['id'],
						        'reliever_status' => 1
					        ]);
					        $reliever->status = 2;
					        if($reliever->current_vessel !== NULL){
						        $reliever->prev_vessel = $reliever->current_vessel;
					        }
                            $reliever->joining_port = NULL;
                            $reliever->joining_date = NULL;
					        $reliever->current_vessel = $berth->vessel->id;
					        $reliever->save();

                            Application_remark::create([
                                'application_id' => $reliever->id,
                                'user_id' => Auth::id(),
                                'user_remark' => 'Proposed to mv ' . $berth->vessel->name
                            ]);


				        }, 5);

				        if($from_application) {
					        return response()->json([
						        'status' => 'success',
						        'vessel_list'=>$this->get_vessel_list(2,$application_id),
						        'seafarer'=>$reliever->status
					        ], 200);
				        }
				        $vessel_berth = Vessel_berth::find($request['berth_id']);
				        return response()->json(['success' => $this->get_crew_list($vessel_berth->vessel_id)], 200);
			        }
		        } else {
			        return response()->json(['status' => 'not found'], 200);
		        }
	        } else {
		        return response()->json(['status' => 'No required data'], 200);
	        }
        } else {
	        return response()->json(['status' => 'Vessel berth not found'], 200);
        }


    }