Skip to content

Commit

Permalink
Sets an octane response on worker error (#102)
Browse files Browse the repository at this point in the history
* Sets an octane response on worker error

* Update Octane.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
nunomaduro and taylorotwell authored Oct 7, 2021
1 parent 27711d8 commit 65b06a0
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/Runtime/Octane/Octane.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Octane implements Client
const DB_SESSION_DEFAULT_TTL = 28800;

/**
* List of octane database sessions.
* List of Octane database sessions.
*
* @var bool
*/
Expand All @@ -43,21 +43,21 @@ class Octane implements Client
];

/**
* The octane response, if any.
* The Octane response, if any.
*
* @var \Laravel\Octane\OctaneResponse|null
*/
protected static $response;

/**
* The octane worker, if any.
* The Octane worker, if any.
*
* @var \Laravel\Octane\Worker|null
*/
protected static $worker;

/**
* Boots an octane worker instance.
* Boots an Octane worker instance.
*
* @param string $basePath
* @param bool $databaseSessionPersist
Expand Down Expand Up @@ -124,7 +124,7 @@ protected static function manageDatabaseSessions($databaseSessionPersist, $datab
}

/**
* Handle the given octane request.
* Handle the given Octane request.
*
* @param \Laravel\Octane\RequestContext $request
* @return \Laravel\Vapor\Runtime\Response
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function handle($request)
}

/**
* Terminates an octane worker instance, if any.
* Terminates an Octane worker instance, if any.
*
* @return void
*/
Expand All @@ -192,17 +192,7 @@ public static function terminate()
}

/**
* Gets the octane worker, if any.
*
* @return \Laravel\Octane\Worker|null
*/
public static function worker()
{
return static::$worker;
}

/**
* Marshal the given octane request context into an Laravel foundation request.
* Marshal the given Octane request context into an Laravel foundation request.
*
* @param \Laravel\Octane\RequestContext $context
* @return array
Expand Down Expand Up @@ -239,10 +229,16 @@ public function respond(RequestContext $context, OctaneResponse $response): void
public function error(Throwable $e, Application $app, Request $request, RequestContext $context): void
{
try {
$app[ExceptionHandler::class]->report($e);
static::$response = new OctaneResponse(
$app[ExceptionHandler::class]->render($request, $e)
);
} catch (Throwable $throwable) {
fwrite(STDERR, $throwable->getMessage());
fwrite(STDERR, $e->getMessage());

static::$response = new OctaneResponse(
new \Illuminate\Http\Response('', 500)
);
}
}

Expand All @@ -257,4 +253,14 @@ protected static function ensureServerSoftware($software)
$_ENV['SERVER_SOFTWARE'] = $software;
$_SERVER['SERVER_SOFTWARE'] = $software;
}

/**
* Get the Octane worker, if any.
*
* @return \Laravel\Octane\Worker|null
*/
public static function worker()
{
return static::$worker;
}
}

0 comments on commit 65b06a0

Please sign in to comment.