mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
reduce code duplication for error handling
This commit is contained in:
parent
68aa34962f
commit
471824d423
3 changed files with 12 additions and 11 deletions
|
|
@ -7,4 +7,13 @@
|
||||||
|
|
||||||
namespace Icewind\SMB\Exception;
|
namespace Icewind\SMB\Exception;
|
||||||
|
|
||||||
class Exception extends \Exception {}
|
class Exception extends \Exception {
|
||||||
|
static public function unknown($path, $error) {
|
||||||
|
$message = 'Unknown error (' . $error . ')';
|
||||||
|
if ($path) {
|
||||||
|
$message .= ' for ' . $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Exception($message, $error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,7 @@ class NativeState {
|
||||||
case 113:
|
case 113:
|
||||||
throw new NoRouteToHostException($path, $error);
|
throw new NoRouteToHostException($path, $error);
|
||||||
default:
|
default:
|
||||||
$message = 'Unknown error (' . $error . ')';
|
throw Exception::unknown($path, $error);
|
||||||
if ($path) {
|
|
||||||
$message .= ' for ' . $path;
|
|
||||||
}
|
|
||||||
throw new Exception($message, $error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,7 @@ class Parser {
|
||||||
case ErrorCodes::SharingViolation:
|
case ErrorCodes::SharingViolation:
|
||||||
throw new FileInUseException($path);
|
throw new FileInUseException($path);
|
||||||
default:
|
default:
|
||||||
$message = 'Unknown error (' . $error . ')';
|
throw Exception::unknown($path, $error);
|
||||||
if ($path) {
|
|
||||||
$message .= ' for ' . $path;
|
|
||||||
}
|
|
||||||
throw new Exception($message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue