1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/lib/Db/MySQL/ExceptionBuilder.php

58 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\Db\MySQL;
use JKingWeb\Arsse\Db\Exception;
use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Db\ExceptionTimeout;
trait ExceptionBuilder {
public static function buildEngineException($code, string $msg): array {
switch ($code) {
case 1205:
return [ExceptionTimeout::class, 'general', $msg];
case 1364:
return [ExceptionInput::class, "engineConstraintViolation", $msg];
case 1366:
return [ExceptionInput::class, 'engineTypeViolation', $msg];
default:
return [Exception::class, 'engineErrorGeneral', $msg];
}
}
2019-01-15 15:51:55 +00:00
public static function buildConnectionException($code, string $msg): array {
switch ($code) {
case 1045:
2022-09-15 14:12:04 +00:00
// @codeCoverageIgnoreStart
2019-01-15 15:51:55 +00:00
case 1043:
case 1044:
case 1046:
case 1049:
case 2001:
case 2002:
case 2003:
case 2004:
case 2005:
case 2007:
case 2009:
case 2010:
case 2011:
case 2012:
case 2015:
case 2016:
case 2017:
case 2018:
case 2026:
case 2028:
2022-09-15 14:12:04 +00:00
// @codeCoverageIgnoreEnd
2019-01-15 15:51:55 +00:00
return [Exception::class, 'connectionFailure', ['engine' => "MySQL", 'message' => $msg]];
default:
return [Exception::class, 'engineErrorGeneral', $msg]; // @codeCoverageIgnore
}
}
}