/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mobirent.gui;

import com.mobirent.abstracttags.Epitomize;

/**
 *
 * @author Budai Attila
 */
public class ExceptionHandler extends Exception {

    private String message = "";

    public ExceptionHandler() {
    }

    {
        System.gc();
    }

    public ExceptionHandler(String msg) {
        Epitomize.isDone = false;

        

        if (msg.equals("TCP open")) {
            message = "Mobil hálózat nem elérhetö.";
            return;
        }
        if (msg.length() > 19 && msg.substring(4, 19).equals(" response code:")) {
            message = respondKiertekel(msg.substring(20, msg.length()));
            return;
        }
        if (msg.substring(0, 1).equals("1")) {
            message = msg.substring(1, msg.length());
            return;
        }

        if (msg.endsWith("denied") || msg.endsWith("API")) {
            message = "Engedélyezze az internethozzáférést!";
            return;
        }
        message = msg + ";";
    }

    private String respondKiertekel(String msg) {

        int respond = 0;
        try {
            respond = Integer.parseInt(msg);
        } catch (Exception e) {
            System.out.println("RespondKiertekel- ben hiba!");
        }
        switch (respond) {
            case 404:
                return "Page not found.";
            case 501:
                return "Flush error.";
            case 500:
                return "Internal Server Error!";
            case 502:
                return "502.";
            case 302:
                return "URL not found.";
            default:
                return respond + "";
        }
    }

    public String getMessage() {
        return message;
    }
}
