\documentclass[10pt,a4paper]{article}

% Packages
\usepackage[margin=0.75in]{geometry}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{fontspec}
\usepackage{listings}
\usepackage{tcolorbox}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{array}
\usepackage{lastpage}

% RAPS Color Scheme
\definecolor{rapsblue}{RGB}{102,126,234}
\definecolor{rapspurple}{RGB}{118,75,162}
\definecolor{rapsgreen}{RGB}{40,167,69}
\definecolor{rapsgray}{RGB}{108,117,125}
\definecolor{rapslight}{RGB}{248,249,250}
\definecolor{rapsdark}{RGB}{52,58,64}
\definecolor{rapserror}{RGB}{220,53,69}
\definecolor{rapswarning}{RGB}{255,193,7}

% Font settings
\setmainfont{Helvetica Neue}
\setmonofont{Consolas}

% Header/Footer
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\color{rapsgray}\small APS Error Codes Reference}
\fancyhead[C]{\color{rapsblue}\textbf{RAPS v4.2.1}}
\fancyhead[R]{\color{rapsgray}\small Page \thepage\ of \pageref{LastPage}}
\fancyfoot[L]{\color{rapsgray}\small Document v1.8 | January 2026}
\fancyfoot[C]{\color{rapsgray}\small rapscli.xyz}
\fancyfoot[R]{\color{rapsgray}\small Professional APS Automation}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}

% Custom commands
\newcommand{\errorcode}[1]{\colorbox{rapserror}{\color{white}\textbf{#1}}}
\newcommand{\warningcode}[1]{\colorbox{rapswarning}{\color{black}\textbf{#1}}}
\newcommand{\rapscmd}[1]{\colorbox{rapslight}{\texttt{\color{rapsblue}#1}}}
\newcommand{\endpoint}[1]{\texttt{\small\color{rapspurple}#1}}

% Code listing style
\lstdefinestyle{raps}{
    backgroundcolor=\color{rapslight},
    basicstyle=\ttfamily\small,
    keywordstyle=\color{rapsblue},
    stringstyle=\color{rapsgreen},
    commentstyle=\color{rapsgray},
    breaklines=true,
    frame=single,
    frameround=tttt,
    rulecolor=\color{rapsgray}
}
\lstset{style=raps}

% Table column types
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

% Title Page
\begin{center}
    \vspace*{2cm}
    {\Huge\color{rapsblue}\textbf{APS API Error Codes Reference}}\\
    \vspace{5mm}
    {\Large\color{rapsgray}Complete Troubleshooting Guide for Autodesk Platform Services}\\
    \vspace{10mm}
    \includegraphics[width=3cm]{raps-logo.png} % Placeholder for logo
    \vspace{10mm}
    
    \begin{tcolorbox}[colback=rapslight,colframe=rapsblue,width=0.8\textwidth]
    {\large\textbf{Document Information}}\\[2mm]
    Version: 1.8\\
    RAPS CLI: v4.2.1\\
    Updated: January 2026\\
    Pages: \pageref{LastPage}
    \end{tcolorbox}
\end{center}

\newpage

% Table of Contents
\tableofcontents
\newpage

% Section 1: Common HTTP Status Codes
\section{Common HTTP Status Codes}

\subsection{Client Error Responses (4xx)}

\begin{longtable}{|p{1.5cm}|p{3cm}|p{6cm}|p{4cm}|}
\hline
\rowcolor{rapslight}
\textbf{Code} & \textbf{Error} & \textbf{Common Causes} & \textbf{RAPS Solution} \\
\hline
\endfirsthead

\hline
\rowcolor{rapslight}
\textbf{Code} & \textbf{Error} & \textbf{Common Causes} & \textbf{RAPS Solution} \\
\hline
\endhead

\errorcode{400} & Bad Request & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Invalid JSON format
\item Missing required fields
\item Invalid parameter values
\end{itemize} & 
\rapscmd{raps --validate}\\
\hline

\errorcode{401} & Unauthorized & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Expired access token
\item Invalid credentials
\item Missing auth header
\end{itemize} & 
\rapscmd{raps auth refresh}\\
\hline

\errorcode{403} & Forbidden & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Insufficient scopes
\item ACC not provisioned
\item User lacks permissions
\end{itemize} & 
\rapscmd{raps auth status --scopes}\\
\hline

\errorcode{404} & Not Found & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Invalid URN
\item Resource deleted
\item Wrong endpoint
\end{itemize} & 
\rapscmd{raps urn verify}\\
\hline

\errorcode{409} & Conflict & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Bucket name taken
\item Duplicate resource
\item Version conflict
\end{itemize} & 
\rapscmd{raps bucket check}\\
\hline

\errorcode{429} & Rate Limited & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Too many requests
\item Quota exceeded
\item Retry after header
\end{itemize} & 
Auto-handled by RAPS\\
\hline

\end{longtable}

\subsection{Server Error Responses (5xx)}

\begin{longtable}{|p{1.5cm}|p{3cm}|p{6cm}|p{4cm}|}
\hline
\rowcolor{rapslight}
\textbf{Code} & \textbf{Error} & \textbf{Common Causes} & \textbf{RAPS Solution} \\
\hline
\endfirsthead

\hline
\rowcolor{rapslight}
\textbf{Code} & \textbf{Error} & \textbf{Common Causes} & \textbf{RAPS Solution} \\
\hline
\endhead

\errorcode{500} & Internal Error & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item APS service issue
\item Temporary outage
\item Server exception
\end{itemize} & 
\rapscmd{raps retry --backoff}\\
\hline

\errorcode{502} & Bad Gateway & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Proxy error
\item Service unavailable
\item Network issue
\end{itemize} & 
\rapscmd{raps health check}\\
\hline

\errorcode{503} & Service Unavailable & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Maintenance mode
\item Overloaded
\item Temporary issue
\end{itemize} & 
Wait and retry\\
\hline

\errorcode{504} & Gateway Timeout & 
\begin{itemize}[leftmargin=*,topsep=0pt,itemsep=0pt]
\item Long operation
\item Network timeout
\item Slow response
\end{itemize} & 
\rapscmd{raps --timeout 300}\\
\hline

\end{longtable}

% Section 2: API-Specific Errors
\section{API-Specific Error Codes}

\subsection{Authentication API}

\begin{tcolorbox}[colback=rapslight,colframe=rapsblue,title=Common Authentication Errors]
\begin{lstlisting}
{
  "developerMessage": "The client_id specified does not have access to the api product",
  "errorCode": "AUTH-001",
  "more info": "https://aps.autodesk.com/en/docs/oauth/v2/errors/"
}
\end{lstlisting}
\end{tcolorbox}

\begin{longtable}{|p{2.5cm}|p{5cm}|p{6cm}|}
\hline
\rowcolor{rapslight}
\textbf{Error Code} & \textbf{Description} & \textbf{Solution} \\
\hline
\endfirsthead

\hline
\rowcolor{rapslight}
\textbf{Error Code} & \textbf{Description} & \textbf{Solution} \\
\hline
\endhead

AUTH-001 & Client ID lacks API access & Enable API in app settings\\
\hline
AUTH-002 & Invalid grant type & Use \texttt{client\_credentials} or \texttt{authorization\_code}\\
\hline
AUTH-003 & Invalid refresh token & Re-authenticate with \rapscmd{raps auth login}\\
\hline
AUTH-004 & Token expired & Run \rapscmd{raps auth refresh}\\
\hline
AUTH-005 & Invalid scope & Check available scopes in app settings\\
\hline
\end{longtable}

\subsection{Data Management API}

\begin{tcolorbox}[colback=red!5,colframe=rapserror,title=Common DM Errors]
When working with BIM360/ACC, most 403 errors are due to missing custom integration setup.
See ACC Provisioning Checklist for detailed steps.
\end{tcolorbox}

\begin{longtable}{|p{2.5cm}|p{5cm}|p{6cm}|}
\hline
\rowcolor{rapslight}
\textbf{Error Code} & \textbf{Description} & \textbf{Solution} \\
\hline
\endfirsthead

\hline
\rowcolor{rapslight}
\textbf{Error Code} & \textbf{Description} & \textbf{Solution} \\
\hline
\endhead

DM-001 & Hub not accessible & Check user permissions\\
\hline
DM-002 & Project not found & Verify project ID and access\\
\hline
DM-003 & Folder permission denied & Request folder access from admin\\
\hline
DM-004 & Version conflict & Use \rapscmd{raps dm versions --latest}\\
\hline
DM-005 & Storage location invalid & Create storage first, then upload\\
\hline
\end{longtable}

\subsection{Model Derivative API}

\begin{center}
\begin{tikzpicture}[scale=0.8]
\node[draw,rounded corners,fill=green!20] (success) at (0,0) {Success};
\node[draw,rounded corners,fill=yellow!20] (pending) at (3,0) {Pending};
\node[draw,rounded corners,fill=red!20] (failed) at (6,0) {Failed};
\node[draw,rounded corners,fill=blue!20] (inprogress) at (9,0) {InProgress};

\draw[->,thick] (pending) -- (inprogress);
\draw[->,thick] (inprogress) -- (success);
\draw[->,thick,dashed] (inprogress) -- (failed);
\end{tikzpicture}
\end{center}

\begin{longtable}{|p{3.5cm}|p{5cm}|p{5cm}|}
\hline
\rowcolor{rapslight}
\textbf{Error Message} & \textbf{Likely Cause} & \textbf{Solution} \\
\hline
\endfirsthead

\hline
\rowcolor{rapslight}
\textbf{Error Message} & \textbf{Likely Cause} & \textbf{Solution} \\
\hline
\endhead

TranslationWorker-InternalFailure & File corrupted or unsupported & Verify file integrity and format\\
\hline
Tr worker fail to download & Source file deleted from OSS & Re-upload file to bucket\\
\hline
Unrecoverable exit code & File too complex & Simplify model or split into parts\\
\hline
Translation timed out & File too large (>1GB) & Reduce file size or wait longer\\
\hline
No viewables found & Wrong output format & Request SVF2 format explicitly\\
\hline
\end{longtable}

% Section 3: Quick Reference
\section{Quick Troubleshooting Guide}

\subsection{Decision Tree}

\begin{center}
\begin{tikzpicture}[
    node distance=2cm,
    decision/.style={diamond, draw=rapsblue, fill=rapslight, text width=3cm, align=center},
    action/.style={rectangle, draw=rapsgreen, fill=green!10, text width=3cm, align=center},
    error/.style={rectangle, draw=rapserror, fill=red!10, text width=3cm, align=center}
]

\node[decision] (start) {Error Code?};
\node[decision, below left=of start] (auth) {401/403?};
\node[decision, below right=of start] (notfound) {404?};
\node[action, below=of auth] (refresh) {\rapscmd{raps auth refresh}};
\node[action, below=of notfound] (verify) {\rapscmd{raps urn verify}};

\draw[->,thick] (start) -- node[left] {Auth} (auth);
\draw[->,thick] (start) -- node[right] {Resource} (notfound);
\draw[->,thick] (auth) -- (refresh);
\draw[->,thick] (notfound) -- (verify);

\end{tikzpicture}
\end{center}

\subsection{RAPS Emergency Commands}

\begin{tcolorbox}[colback=rapslight,colframe=rapsgreen,title=Quick Fixes]
\begin{lstlisting}
# Authentication issues
raps auth refresh
raps auth login --force
raps auth status --verbose

# API failures
raps health check
raps retry --max-attempts 5
raps logs --level error

# Debug mode
raps --verbose --debug <command>
export RAPS_DEBUG=true
\end{lstlisting}
\end{tcolorbox}

% Section 4: Prevention Best Practices
\section{Error Prevention Best Practices}

\subsection{Proactive Error Handling}

\begin{enumerate}
\item \textbf{Always validate inputs}
\begin{lstlisting}
raps validate <file> --schema aps
raps bucket check <name> --before-create
\end{lstlisting}

\item \textbf{Use retry logic}
\begin{lstlisting}
raps config set retry.enabled true
raps config set retry.max-attempts 5
raps config set retry.backoff exponential
\end{lstlisting}

\item \textbf{Monitor rate limits}
\begin{lstlisting}
raps stats --api-calls
raps config set rate-limit.warning 80%
\end{lstlisting}

\item \textbf{Enable comprehensive logging}
\begin{lstlisting}
raps config set log.level debug
raps config set log.destination ./logs/
\end{lstlisting}
\end{enumerate}

\subsection{Common Pitfalls to Avoid}

\begin{itemize}[leftmargin=*]
\item \textbf{Never} hardcode tokens - use \rapscmd{raps auth}
\item \textbf{Always} check bucket existence before upload
\item \textbf{Remember} ACC requires custom integration setup
\item \textbf{Monitor} token expiry - refresh proactively
\item \textbf{Validate} URN encoding - use \rapscmd{raps urn encode}
\end{itemize}

% Footer
\vfill
\begin{tcolorbox}[colback=rapsdark,colframe=rapsdark]
\color{white}
\begin{center}
\textbf{Need Help?}\\[2mm]
📧 support@rapscli.xyz | 💬 Discord: discord.gg/raps | 🌐 rapscli.xyz\\[2mm]
This document is part of RAPS Professional Documentation Suite v4.2.1
\end{center}
\end{tcolorbox}

\end{document}