Skip to content

Commit

Permalink
fix: give friendlier error messages during updates #633
Browse files Browse the repository at this point in the history
Before, access REST API resources resulted in a PHP error traceback which could cause unnecessary concern. This change will allow both endpoints and forms to give a friendlier, more informative notice.
  • Loading branch information
jaredhendrickson13 committed Jan 11, 2025
1 parent 21188aa commit c181ed6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,18 @@ class Endpoint {
$nq_class_name = $this->get_class_shortname();

# Specify the PHP code to write to the Endpoints index.php file
$unavailable_error = new ServiceUnavailableError(
message: 'This resource is either not installed or is currently updating. Please try again later.',
response_id: 'ENDPOINT_UNAVAILABLE',
);
$unavailable_error_json = json_encode($unavailable_error->to_representation());
$code =
"<?php\n" .
"require_once('RESTAPI/Endpoints/$nq_class_name.inc');\n" .
"\$include = include('RESTAPI/Endpoints/$nq_class_name.inc');\n" .
"if (!\$include) {\n" .
" echo '$unavailable_error_json';\n" .
" exit(503);\n" .
"}\n" .
"echo (new $fq_class_name())->process_request();\n" .
"header('Referer: no-referrer');\n" .
"session_destroy();\n" .
Expand Down
17 changes: 9 additions & 8 deletions pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,15 @@ class Form {

# Specify the PHP code to write to the Endpoints index.php file
$code =
"<?php
require_once('RESTAPI/Forms/" .
$nq_class_name .
".inc');
require_once('guiconfig.inc');
(new " .
$fq_class_name .
'())->print_form();';
"<?php\n" .
"require_once('guiconfig.inc');\n" .
"\$include = include('RESTAPI/Forms/$nq_class_name.inc');\n" .
"if (!\$include) {\n" .
" echo '<h1>Service Unavailable</h1>';\n" .
" echo 'This resource is either not installed or is currently updating. Please try again later.';\n" .
" exit(503);\n" .
"}\n" .
"(new $fq_class_name())->print_form();\n";

# Assign the absolute path to the file. Assume index.php filename if not specified.
$filename = "/usr/local/www/$this->url";
Expand Down

0 comments on commit c181ed6

Please sign in to comment.