Skip to content

Commit

Permalink
inline return for exceptions on 'src/Admin'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassouzavieira committed May 15, 2024
1 parent 84cd726 commit 12b1dd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
18 changes: 6 additions & 12 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public static function statistics(Connection $connection)
} catch (ClientException $exception) {
// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand All @@ -97,8 +96,7 @@ public static function time(Connection $connection): float
} catch (ClientException $exception) {
// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand Down Expand Up @@ -127,8 +125,7 @@ public static function tasks(Connection $connection): ArrayList
} catch (ClientException $exception) {
// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand Down Expand Up @@ -160,8 +157,7 @@ public static function flushWal(Connection $connection, bool $waitForSync = true
} catch (ClientException $exception) {
// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand Down Expand Up @@ -200,8 +196,7 @@ public static function walProperties(Connection $connection): array
$message = "Not Implemented";
}

$serverException = new ServerException($message, $exception, $code);
throw $serverException;
throw new ServerException($message, $exception, $code);
}
}

Expand All @@ -226,8 +221,7 @@ public static function walTransactions(Connection $connection): array
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$message = isset($response['errorMessage']) ? $response['errorMessage'] : "Unknown error";
$code = isset($response['errorNum']) ? $response['errorNum'] : $exception->getResponse()->getStatusCode();
$serverException = new ServerException($message, $exception, $code);
throw $serverException;
throw new ServerException($message, $exception, $code);
}
}
}
12 changes: 4 additions & 8 deletions src/Admin/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public static function engine(Connection $connection): string
return $data['name'];
} catch (\Exception $exception) {
// Unknown error.
$serverException = new ServerException($exception->getMessage(), $exception, $exception->getCode());
throw $serverException;
throw new ServerException($exception->getMessage(), $exception, $exception->getCode());
}
}

Expand All @@ -88,8 +87,7 @@ public static function role(Connection $connection): string
return strtolower($data['role']);
} catch (\Exception $exception) {
// Unknown error.
$serverException = new ServerException($exception->getMessage(), $exception, $exception->getCode());
throw $serverException;
throw new ServerException($exception->getMessage(), $exception, $exception->getCode());
}
}

Expand Down Expand Up @@ -117,8 +115,7 @@ public static function isAvailable(Connection $connection): bool

// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand All @@ -139,8 +136,7 @@ public static function logLevel(Connection $connection): array
return $data;
} catch (BadResponseException $exception) {
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}
}
6 changes: 2 additions & 4 deletions src/Admin/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ public function save(): bool
} catch (ClientException $exception) {
// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand Down Expand Up @@ -253,8 +252,7 @@ public function delete(): bool

// Unknown error.
$response = json_decode((string)$exception->getResponse()->getBody(), true);
$serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);
throw $serverException;
throw new ServerException($response['errorMessage'], $exception, $response['errorNum']);
}
}

Expand Down

0 comments on commit 12b1dd3

Please sign in to comment.