playwright-testrail-sync
Version:
TestRail Integration for Playwright with comprehensive logging and error handling
61 lines • 2.02 kB
JavaScript
;
/**
* Error handler
* Handles TestRail API error processing and transformation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleApiError = handleApiError;
/**
* Handle and transform API errors
*/
function handleApiError(error) {
if (error.response) {
const status = error.response.status;
let userFriendlyMessage = "API Error";
// Provide user-friendly error messages for common issues
switch (status) {
case 401:
userFriendlyMessage =
"Authentication failed - check your username and API key";
break;
case 403:
userFriendlyMessage = "Access denied - check your TestRail permissions";
break;
case 404:
userFriendlyMessage =
"Resource not found - check your project ID and suite ID";
break;
case 422:
userFriendlyMessage = "Invalid data - check your configuration values";
break;
case 500:
userFriendlyMessage = "TestRail server error - try again later";
break;
default:
userFriendlyMessage = error.response.data?.error || "API Error";
}
return {
error: userFriendlyMessage,
details: error.response.data?.details || error.response.statusText,
status: status,
response: error.response.data,
};
}
else if (error.request) {
return {
error: "Network Error",
details: "No response received from TestRail API - check your host URL and network connection",
status: 0,
response: error.request,
};
}
else {
return {
error: "Request Error",
details: error.message,
status: 0,
response: null,
};
}
}
//# sourceMappingURL=error-handler.js.map