Connection Troubleshooting
This guide helps you diagnose and resolve common connection issues with your APSO backend.
Quick Diagnostics
Run these checks first:
# 1. Is the server running?
curl http://localhost:3001/health
# 2. Can you reach the database?
psql $DATABASE_URL -c "SELECT 1"
# 3. Is auth working?
curl -X POST http://localhost:3001/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password"}'Connection Errors
ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:3001Cause: Server is not running or wrong port.
Solutions:
- Start the server:
npm run dev - Check the port in your
.env:PORT=3001 - Verify nothing else is using the port:
lsof -i :3001
ENOTFOUND
Error: getaddrinfo ENOTFOUND api.example.comCause: DNS resolution failed.
Solutions:
- Check the URL spelling
- Verify DNS is working:
nslookup api.example.com - Try using IP address instead
ETIMEDOUT
Error: connect ETIMEDOUTCause: Server unreachable or too slow.
Solutions:
- Check network connectivity
- Verify firewall rules
- Check if server is overloaded
Authentication Errors
401 Unauthorized
{
"statusCode": 401,
"message": "Unauthorized"
}Possible causes:
- Missing auth header
- Expired token
- Invalid token
Solutions:
# Check if token is included
curl -v http://localhost:3001/api/v1/projects
# Refresh your token
curl -X POST http://localhost:3001/api/auth/refresh \
-H "Content-Type: application/json" \
-d '{"refreshToken": "your-refresh-token"}'403 Forbidden
{
"statusCode": 403,
"message": "Forbidden"
}Possible causes:
- Accessing another organization’s data
- Missing organization context
- Insufficient permissions
Solutions:
- Verify you’re accessing your own organization’s resources
- Check
X-Organization-Idheader if multi-tenant - Verify user has required role/permissions
Invalid Token Format
{
"statusCode": 401,
"message": "Invalid token"
}Solutions:
- Ensure format is
Bearer <token>(with space) - Check token isn’t truncated
- Verify you’re using the access token, not refresh token
Database Errors
Connection Refused
Error: connect ECONNREFUSED 127.0.0.1:5432Solutions:
# Check if PostgreSQL is running
docker ps | grep postgres
# or
pg_isready -h localhost -p 5432
# Start PostgreSQL
docker start apso-postgres
# or
brew services start postgresqlAuthentication Failed
Error: password authentication failed for user "apso"Solutions:
- Verify DATABASE_URL credentials
- Check pg_hba.conf authentication rules
- Reset password:
docker exec -it apso-postgres psql -U postgres -c \
"ALTER USER apso WITH PASSWORD 'newpassword';"Database Does Not Exist
Error: database "apso_dev" does not existSolutions:
# Create the database
docker exec -it apso-postgres createdb -U postgres apso_dev
# Or run setup
npm run db:setupToo Many Connections
Error: too many connections for role "apso"Solutions:
- Reduce connection pool size in
.apsorc - Increase PostgreSQL max_connections
- Use a connection pooler (PgBouncer)
{
"database": {
"pool": {
"max": 10
}
}
}Request Errors
400 Bad Request
{
"statusCode": 400,
"message": "Validation failed",
"errors": [...]
}Solutions:
- Check required fields are present
- Verify data types match schema
- Review validation error messages
404 Not Found
{
"statusCode": 404,
"message": "Not found"
}Possible causes:
- Resource doesn’t exist
- Wrong endpoint URL
- Resource is soft-deleted
- Resource belongs to different organization
Solutions:
- Verify the ID is correct
- Check the endpoint path
- Confirm resource exists in database
422 Unprocessable Entity
{
"statusCode": 422,
"message": "Unprocessable Entity",
"errors": [
{"field": "email", "message": "Email already exists"}
]
}Solutions:
- Review specific field errors
- Check unique constraint violations
- Validate enum values
CORS Errors
Browser Console Error
Access to XMLHttpRequest at 'http://localhost:3001' has been blocked by CORS policySolutions:
- Configure CORS in your APSO server:
// src/main.ts
app.enableCors({
origin: ['http://localhost:3000'],
credentials: true,
});- Or configure in
.apsorc:
{
"api": {
"cors": {
"origin": ["http://localhost:3000"],
"credentials": true
}
}
}SSL/TLS Errors
Certificate Errors
Error: unable to verify the first certificateSolutions:
- For development, add
?sslmode=disable(not for production) - Install proper SSL certificates
- Use
NODE_TLS_REJECT_UNAUTHORIZED=0for testing only
Performance Issues
Slow Responses
Diagnostics:
# Check query performance
DEBUG=typeorm:query npm run dev
# Profile endpoint
time curl http://localhost:3001/api/v1/projectsSolutions:
- Add database indexes
- Reduce include depth
- Implement pagination
- Enable query caching
Timeout Errors
Error: Request timeoutSolutions:
- Increase client timeout
- Optimize slow queries
- Add indexes to frequently queried fields
- Consider pagination for large datasets
Debug Mode
Enable verbose logging:
# Environment variable
DEBUG=* npm run dev
# Or in .env
DEBUG=apso:*,typeorm:queryGetting Help
If you’re still stuck:
- Check server logs for detailed error messages
- Review the FAQ
- Search the GitHub issuesÂ
- Join the Discord communityÂ
Related
Last updated on